Skip to content

Instantly share code, notes, and snippets.

@dpick
Created October 26, 2012 04:29
Show Gist options
  • Save dpick/3956825 to your computer and use it in GitHub Desktop.
Save dpick/3956825 to your computer and use it in GitHub Desktop.
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