Advertisement
Guest User

Untitled

a guest
May 15th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.69 KB | None | 0 0
  1. import scala.io.Source
  2.  
  3. object zad3 extends App {
  4.  
  5.     def histogram(max: Int): Unit = {
  6.         val input = Source.fromFile("ogniem.txt").getLines
  7.  
  8.         val formattedInput = input.foldLeft(Seq.empty[Seq[Char]])(
  9.             (acc: Seq[Seq[Char]], curr: String) =>
  10.                 acc :+ curr.filter(_.isLetter).toLowerCase.toList
  11.         ).flatten
  12.  
  13.         val groupedInput = formattedInput.groupBy(identity).map(n => (n._1, n._2.size)).toList.sorted
  14.  
  15.         groupedInput.foreach(n => n._2 match {
  16.             case num if (num > max) => println(n._1 + " -> " + "*"*max)
  17.             case num => println(n._1 + " -> " + "*"*n._2)
  18.         })
  19.     }  
  20.    
  21.     histogram(200)
  22.  
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement