Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import scala.io.Source
- object zad3 extends App {
- def histogram(max: Int): Unit = {
- val input = Source.fromFile("ogniem.txt").getLines
- val formattedInput = input.foldLeft(Seq.empty[Seq[Char]])(
- (acc: Seq[Seq[Char]], curr: String) =>
- acc :+ curr.filter(_.isLetter).toLowerCase.toList
- ).flatten
- val groupedInput = formattedInput.groupBy(identity).map(n => (n._1, n._2.size)).toList.sorted
- groupedInput.foreach(n => n._2 match {
- case num if (num > max) => println(n._1 + " -> " + "*"*max)
- case num => println(n._1 + " -> " + "*"*n._2)
- })
- }
- histogram(200)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement