Created
December 9, 2012 07:13
-
-
Save 8bit-pixies/4243721 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
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