Skip to content

Instantly share code, notes, and snippets.

@ltw
Forked from dpick/gist:3956825
Created October 26, 2012 18:21
Show Gist options
  • Save ltw/3960488 to your computer and use it in GitHub Desktop.
Save ltw/3960488 to your computer and use it in GitHub Desktop.
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