-
-
Save ltw/3960488 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
class Letterpress | |
def self.run(board) | |
all_words = File.open('/usr/share/dict/words').readlines.map! { |line| line.strip.chomp } | |
valid_words = all_words.select { |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.sort {|x,y| y.length <=> x.length} | |
end | |
end | |
Letterpress.run ARGV |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment