Skip to content

Instantly share code, notes, and snippets.

@naush
Created March 17, 2012 14:41
Show Gist options
  • Save naush/2060175 to your computer and use it in GitHub Desktop.
Save naush/2060175 to your computer and use it in GitHub Desktop.
unless ARGV.size == 2
puts "USAGE: ruby guess.rb ACKRCKOOLCWZ 5"
exit 1
end
letters = ARGV[0]
limit = ARGV[1]
words = Hash.new { |h, word| h[word] = false }
File.open("/usr/share/dict/words") do |file|
file.each do |line|
words[line.strip.downcase] = true
end
end
guesses = []
letters.downcase.split(//).permutation(limit.to_i).to_a.each do |permutation|
guess = permutation.join
guesses << guess if words[guess]
end
guesses.uniq.each do |guess|
puts guess
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment