Skip to content

Instantly share code, notes, and snippets.

@8bit-pixies
Created December 9, 2012 07:13
Show Gist options
  • Save 8bit-pixies/4243721 to your computer and use it in GitHub Desktop.
Save 8bit-pixies/4243721 to your computer and use it in GitHub Desktop.
dict = File.open('selected_four-letter_words.txt').map {|word| word.chomp}
#grab the two words so that you know what you're comparing with!
def one_letter(input,dict)
output = []
dict.each do |word|
letterDiff = 0
word.split('').to_enum.with_index {|letter,i| letterDiff = letterDiff+1 if letter == input[i]}
output << word if letterDiff == 3
end
output
end
puts one_letter("best",dict).length
#bonus one
dict.each {|word| puts "#{word}" if one_letter(word,dict).length == 33}
#bonus two
oneStep = one_letter("best",dict)
twoStep = []
oneStep.each {|word| twoStep.concat(one_letter(word,dict))}
threeStep = []
twoStep.each {|word| threeStep.concat(one_letter(word,dict))}
bestSteps = oneStep.concat(twoStep).concat(threeStep).uniq
puts "#{bestSteps.length} different words can be reached from best in three steps or less (including itself)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment