Created
October 26, 2012 04:29
-
-
Save dpick/3956825 to your computer and use it in GitHub Desktop.
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
board = ["m", "w", "e", "t", "p", "e", "q", "i", "x", "a", "h", "v", "f", "f", "y", "j", "n", "l", "j", "h", "w", "c", "e", "s", "r"] | |
all_words = File.open('/usr/share/dict/words').readlines.map! { |line| line.strip.chomp } | |
valid_words = all_words.reject { |w| w =~ /[^#{board.join}]/ } | |
valid_words = valid_words.select do |w| | |
bool = true | |
bool = false if w.size <= 2 | |
split_word = w.downcase.split('') | |
split_word.each do |let| | |
bool = false unless split_word.count(let) <= board.count(let) | |
end if bool | |
bool | |
end | |
p valid_words |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment