Last active
December 18, 2015 16:19
-
-
Save UberMouse/5811001 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array("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") | |
.filter(_.length > 0) | |
.map(process) | |
.foreach(println) | |
def process(line:String) = { | |
val cleanedLine = "[^a-z]*".r.replaceAllIn(line.toLowerCase, "") | |
cleanedLine.toCharArray | |
.groupBy(identity) | |
.map(x => (x._1, x._2.length)) | |
.toSeq | |
.sortWith(_._2 > _._2) | |
.map(_._2) | |
.zip(26 to 1 by -1) | |
.foldLeft(0)((sum, next) => sum + next._1 * next._2) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment