Last active
December 16, 2020 13:11
-
-
Save ajosanchez/ae7ec853135ec38ef46c to your computer and use it in GitHub Desktop.
This will help you crack those tricky terminals in the Fallout series. Just run this ruby script and enter each word separated only with a slash and no spaces (ex: kid/cat/pop/dog). It will display each words' total matches minus any words that had no matches. Then once you guess enter in the guess word with the likeness returned from the termin…
This file contains hidden or 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
class Hack | |
def initialize words | |
@words = words.downcase.split(/\/|\s|,\s|\,/) | |
@splitwords = [] | |
@words.each { |w| @splitwords << w.split('') } | |
show_likely | |
end | |
def deduct | |
@match_matrix.each_key do |w| | |
if @match_matrix[w].values.inject(0) {|sum, v| sum + v} <= w.length | |
@match_matrix.delete(w) | |
end | |
end | |
end | |
def show_likely | |
@match_matrix = {} | |
@words.each do |w| | |
@words.each_with_index do |ww, i| | |
i == 0 ? @match_matrix[w] = {ww => 0} : @match_matrix[w].merge!({ww => 0}) | |
end | |
end | |
@splitwords.each do |word| | |
word.each_with_index do |letter, i| | |
@splitwords.each do |wordword| | |
if letter == wordword[i] | |
@match_matrix[word.join][wordword.join] += 1 | |
end | |
end | |
end | |
end | |
deduct | |
output | |
end | |
def comb str | |
hint = str.downcase.split(/\/|\,|\s|,\s/) | |
@match_matrix.delete(hint[0]) | |
@match_matrix.each_value do |v| | |
if v[hint[0]] != hint[1].to_i | |
@match_matrix.each_value {|q| q.delete(@match_matrix.key(v))} | |
@match_matrix.delete(@match_matrix.key(v)) | |
end | |
end | |
@match_matrix.each_value {|v| v.delete(hint[0])} | |
output | |
end | |
def output | |
puts "Here's what we got left..." | |
@match_matrix.each_key do |k| | |
print "#{k}".ljust(15) | |
print "#{@match_matrix[k].values.count { |v| v > 0}-1} word matches " | |
print "#{(@match_matrix[k].values.inject(0) {|sum, v| sum + v})-(k.length)} letter matches" | |
print "\n" | |
end | |
end | |
end | |
puts "enter list separated by a dash, no spaces (ex: dog/cat/hop)" | |
input = gets.chomp | |
h = Hack.new(input) | |
puts "\n" | |
while input != "quit" | |
puts "Input your word and likeness with a slash between (ex: foot/2) or quit to exit:" | |
input = gets.chomp | |
h.comb(input) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ok, much improved over the first iteration, it shows word count matches as well as letter matches which don't matter as much. it also updates these counts for each guess/likeness entered.