Skip to content

Instantly share code, notes, and snippets.

@jklmli
Last active December 12, 2015 03:09
Show Gist options
  • Save jklmli/4705136 to your computer and use it in GitHub Desktop.
Save jklmli/4705136 to your computer and use it in GitHub Desktop.
val lines: Array[String] = scala.io.Source.fromFile(args(0)).getLines().toArray
val numberOfLinesToRead: Int = lines.head.toInt
lines
.tail
.take(numberOfLinesToRead)
.zipWithIndex
.foreach{case (str: String, index: Int) => {
val validCharacters: String = str
.filter { Character.isLetter(_) }
.toLowerCase
val frequencies: Iterable[Int] = validCharacters
.groupBy { identity }
.values
.map { _.length }
val descendingFrequencies: Seq[Int] = frequencies
.toSeq
.sorted
.reverse
val maxBeauty: Int = (descendingFrequencies zip (26 to 1 by -1))
.map { case (freq: Int, multiplier: Int) => freq * multiplier }
.sum
println(s"Case #$index: $maxBeauty")
}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment