fork download
  1. import scala.io.Source.{fromFile, stdin}
  2.  
  3. object Main {
  4. def main(args: Array[String]) {
  5. val input = if (args.length >= 1) fromFile(args(0)) else stdin
  6. input.getLines.filterNot(_.isEmpty).map(beauty).foreach(println)
  7. }
  8.  
  9. def beauty(s: String) = s // "abcC!"
  10. .filter(_.isLetter) // "abcC"
  11. .toLowerCase // "abcc"
  12. .groupBy(identity) // [a -> a, b -> b, c -> cc]
  13. .mapValues(_.size) // [a -> 1, b -> 1, c -> 2]
  14. .values.toList // [1, 1, 2]
  15. .sortWith(_ > _) // [2, 1, 1]
  16. .zip(26 to 1 by -1) // [(2, 26), (1, 25), (1, 24)]
  17. .map(x => x._1 * x._2) // [52, 25, 24]
  18. .sum // 101
  19. }
  20.  
Success #stdin #stdout 0.44s 383232KB
stdin
ABbCcc
Good luck in the Facebook Hacker Cup this year!
Ignore punctuation, please :)
Sometimes test cases are hard to make up.
So I just go consult Professor Dalves
stdout
152
754
491
729
646