Created
December 11, 2011 20:07
-
-
Save kaja47/1462460 to your computer and use it in GitHub Desktop.
Scrabble
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
val letters = Map( | |
'a' -> 1, 'é' -> 3, 'k' -> 1, 'r' -> 1, 'ů' -> 4, | |
'á' -> 2, 'ě' -> 3, 'l' -> 1, 'ř' -> 4, 'v' -> 1, | |
'b' -> 3, 'f' -> 5, 'm' -> 2, 's' -> 1, 'x' -> 10, | |
'c' -> 2, 'g' -> 5, 'n' -> 1, 'š' -> 4, 'y' -> 2, | |
'č' -> 4, 'h' -> 2, 'ň' -> 6, 't' -> 1, 'ý' -> 4, | |
'd' -> 1, 'i' -> 1, 'o' -> 1, 'ť' -> 7, 'z' -> 2, | |
'ď' -> 8, 'í' -> 2, 'ó' -> 7, 'u' -> 2, 'ž' -> 4, | |
'e' -> 1, 'j' -> 2, 'p' -> 1, 'ú' -> 5) withDefaultValue 0 | |
/* ninja mode on | |
val letters = ( | |
Map(1 -> "adeiklnoprstv", 2 -> "jyumáíchz", 3 -> "béě", 4 -> "čýšžřů", 5 -> "fgú", 6 -> "ň", 7 -> "ťó", 8 -> "ď", 10 -> "x") | |
flatMap { case (k, vs) => vs map { _ -> k } } withDefaultValue 0 | |
) | |
*/ | |
val words = io.Source.fromFile("seznam_slov") getLines | |
val wordsScore = words map { w => w -> (w map letters sum) } toSeq | |
val ordered = wordsScore sortBy { _._2 } reverse | |
ordered take 10 foreach println |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment