Created
May 7, 2013 06:22
-
-
Save photomattmills/5530595 to your computer and use it in GitHub Desktop.
how to cheat at letterpress
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
#this uses /usr/share/dict/words, which isn't terribly compatible with letterpress. This is just a proof of concept, please don't cheat. Also, it's fairly slow; there's probably a better way to exclude things quickly. | |
def list_words(letters, length) | |
words = File.read("/usr/share/dict/words").split "\n" | |
word_arrays = words.map{|word| word.downcase.split("") } | |
accepted_word_arrays = word_arrays.select{|word_array| check_word(word_array, letters, length)} | |
words = accepted_word_arrays.map{|word_array| word_array.join("") }.compact | |
words.select!{|word| word.length >= length } | |
words.sort!{|wa,wb| wa.length <=> wb.length } | |
end | |
def check_word(word_array, letters, length) | |
word_array.each do |letter| | |
if letters.include? letter | |
letters = letters - [letter] | |
else | |
return false | |
end | |
end | |
return true | |
end | |
puts list_words("vxeiomnaegrygkkzxtsbewtya".split(""), 8) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment