Skip to content

Instantly share code, notes, and snippets.

@photomattmills
Created May 7, 2013 06:22
Show Gist options
  • Save photomattmills/5530595 to your computer and use it in GitHub Desktop.
Save photomattmills/5530595 to your computer and use it in GitHub Desktop.
how to cheat at letterpress
#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