Created
January 20, 2012 18:10
-
-
Save ajkovar/1648750 to your computer and use it in GitHub Desktop.
hack night
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
DICTIONARY = | |
[ | |
"amalar", | |
"noema", | |
"clemiso", | |
"hidromuria", | |
"ambonio", | |
"sustalo", | |
"incopelusa", | |
"novalo", | |
"arnilla", | |
"espejunar", | |
"apeltronar", | |
"reduplimir", | |
"trimalciato", | |
"ergomanina", | |
"filulas", | |
"cariaconcia", | |
"tordulaba", | |
"hurgalios", | |
"orfelunios", | |
"entreplumaban", | |
"ulucordio", | |
"encrestoriaba", | |
"extrayuxtaba", | |
"clinon" | |
] | |
TILES = | |
[ | |
"a2", | |
"a2", | |
"a2", | |
"i4", | |
"w5", | |
"n1", | |
"r12", | |
"e1", | |
"g6", | |
"f7", | |
"s2", | |
"e1", | |
"l7", | |
"t8", | |
"r12", | |
"l7", | |
"h8", | |
"n1", | |
"f7", | |
"b8", | |
"r12", | |
"a2", | |
"u9", | |
"g6", | |
"i4", | |
"t8", | |
"l7", | |
"q9", | |
"o3", | |
"d2", | |
"s2", | |
"f7", | |
"n1", | |
"u9" | |
] | |
def parse_tiles tiles | |
tiles.map { |tile| [tile[0].chr, tile[1..-1].to_i]}.group_by { |tuple| tuple.first } | |
end | |
def get_valid_words words | |
words.find_all do |word| | |
tile_hash = parse_tiles TILES | |
word.split("").all? do |letter| | |
(tile_hash[letter] || []).pop | |
end | |
end | |
end | |
puts get_valid_words DICTIONARY |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment