Skip to content

Instantly share code, notes, and snippets.

@dkam
Last active September 20, 2021 10:10
Show Gist options
  • Save dkam/78ee4eb6e6214746aa09 to your computer and use it in GitHub Desktop.
Save dkam/78ee4eb6e6214746aa09 to your computer and use it in GitHub Desktop.
#/usr/bin/env ruby
# Original http://code.activestate.com/recipes/576590-fallout-3-terminal-hacking-minigame-cracker/
## Get all available words
words = []
loop do
print "word> "
line = gets.chomp
break if line.empty?
words << line
end
word_matrix = {}
words.each do |word|
word_matrix[word] = {}
word_matrix.keys.each do |key|
match = 0
key.each_char.with_index do |char, i|
match += 1 if char == word[i]
end
word_matches = word_matrix[key]
word_matches[word] = match
word_matches = word_matrix[word]
word_matches[key] = match
end
end
word_matrix.keys.each do |key|
word_matches = word_matrix[key]
nonzero = 0
sum = 0
word_matches.keys.each do |word|
if word != key
if word_matches[word] > 0
nonzero += 1
sum += word_matches[word]
end
end
end
if nonzero > 0
puts "#{key} matches #{nonzero} avg #{sum/nonzero}"
end
end
narrowed = words.uniq
loop do
guesses = []
print "guess> "
guess = gets.chomp
break if guess.empty?
print "matches> "
matches = gets.chomp.to_i
word_matches = word_matrix[guess]
word_matches.keys.each {|word| guesses << word if word_matches[word] == matches }
narrowed = narrowed & guesses.uniq
narrowed.each {|word| puts word}
end
__END__
possibility
survivalist
remembering
engineering
influential
eliminating
explanation
discovering
destructive
threatening
mistrusting
containment
nondescript
distinguish
surrounding
programming
remembering matches 15 avg 2
survivalist matches 15 avg 1
surrounding matches 15 avg 2
influential matches 15 avg 1
programming matches 15 avg 2
explanation matches 15 avg 1
threatening matches 15 avg 2
possibility matches 15 avg 1
mistrusting matches 15 avg 3
engineering matches 15 avg 2
eliminating matches 15 avg 2
containment matches 15 avg 1
discovering matches 15 avg 3
nondescript matches 15 avg 1
destructive matches 15 avg 2
distinguish matches 15 avg 2
guess> discovering
matches> 3
destructive
programming
eliminating
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment