Skip to content

Instantly share code, notes, and snippets.

@naush
Created March 18, 2012 07:03
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save naush/2069501 to your computer and use it in GitHub Desktop.
Save naush/2069501 to your computer and use it in GitHub Desktop.
unless ARGV.size == 2
puts "USAGE: ruby draw_something.rb ACKRCKOOLCWZ 5"
exit 1
end
letters = ARGV[0].downcase.split(//).sort
length = ARGV[1].to_i
require 'open-uri'
uri = 'http://static.iminlikewithyou.com/drawsomething/wordlist.csv'
words = open(uri) { |resource| resource.read }.split("\n")
words = words.map { |words| words.split(',').first }
words = words.select { |word| word.length == length }
def valid?(word, letters)
word_index = letters_index = 0
while word_index < word.length && letters_index < letters.length
if word[word_index] == letters[letters_index]
word_index = word_index + 1
end
letters_index = letters_index + 1
end
return word_index == word.length
end
guesses = []
words.each do |word|
guesses << word if valid?(word.split(//).sort, letters)
end
guesses.each do |guess|
puts guess
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment