Last active
October 6, 2016 19:42
-
-
Save squito/96af61a3fd877ac03cfb3dee9651c64f to your computer and use it in GitHub Desktop.
can_build_from_puzzler
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 dictionary = Map( | |
"a" -> Set("apple", "ant"), | |
"b" -> Set("banana", "barn") | |
) | |
// lets count how many times each letter occurs in all words in our dictionary | |
val letters = dictionary.values.flatMap {x => x.flatMap {_.toCharArray} } | |
val letterCounts = letters.groupBy(identity).mapValues(_.size) | |
letterCounts.toArray.sorted.foreach{println} | |
//output: | |
(a,2) | |
(b,1) | |
(e,1) | |
(l,1) | |
(n,2) | |
(p,1) | |
(r,1) | |
(t,1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment