Skip to content

Instantly share code, notes, and snippets.

@squito
Last active October 6, 2016 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save squito/96af61a3fd877ac03cfb3dee9651c64f to your computer and use it in GitHub Desktop.
Save squito/96af61a3fd877ac03cfb3dee9651c64f to your computer and use it in GitHub Desktop.
can_build_from_puzzler
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