Skip to content

Instantly share code, notes, and snippets.

@UberMouse
Last active December 18, 2015 16:19
Show Gist options
  • Save UberMouse/5811001 to your computer and use it in GitHub Desktop.
Save UberMouse/5811001 to your computer and use it in GitHub Desktop.
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