Skip to content

Instantly share code, notes, and snippets.

@tenderlove
Last active April 4, 2019 00:36
Show Gist options
  • Select an option

  • Save tenderlove/f6d47e25c7cf8a7d5216 to your computer and use it in GitHub Desktop.

Select an option

Save tenderlove/f6d47e25c7cf8a7d5216 to your computer and use it in GitHub Desktop.

Revisions

  1. tenderlove revised this gist Nov 12, 2015. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions fallout.rb
    Original file line number Diff line number Diff line change
    @@ -34,6 +34,14 @@
    # was 0, so I re-ran the program like this:
    #
    # ```
    # $ ruby fallout.rb CASTE/LINES/ALTER/OFFER/KEEPS/HAVEN/SPEED/BASIC ALTER:0
    # ["CASTE", "BASIC", "KEEPS"]
    # ```
    #
    # The program tells me to pick "CASTE", so I did, and the terminal said the
    # score is 0, so I re-ran the program like this:
    #
    # ```
    # $ ruby fallout.rb CASTE/LINES/ALTER/OFFER/KEEPS/HAVEN/SPEED/BASIC ALTER:0/CASTE:0
    # ["KEEPS"]
    # ```
  2. tenderlove revised this gist Nov 12, 2015. 1 changed file with 24 additions and 19 deletions.
    43 changes: 24 additions & 19 deletions fallout.rb
    Original file line number Diff line number Diff line change
    @@ -3,10 +3,14 @@
    #
    # Usage:
    #
    # Make your first guess in the terminal, and it will give you a score. Then
    # run this program with a '/' separated list of possible words, and another
    # '/' separated list of words and scores where the word and score are separated
    # by a ':'
    # Run the program once with a list of words in the terminal. The program will
    # output a list, and the first word in the list is the word you should pick
    # because it will eliminate the most possibilities.
    #
    # If that word is incorrect, then re-run the program with two lists, first the
    # list of words, and second the list of guesses you made plus the score. The
    # program will output a list, where the first word in the list is the next
    # optimal guess.
    #
    # In this example, the words shown in my terminal were:
    #
    @@ -19,36 +23,37 @@
    # SPEED
    # BASIC
    #
    # The first word I chose was "CASTE", and the terminal said it scored 0, so
    # I ran this:
    # First run the program with a list of words like this:
    #
    # ```
    # $ ruby fallout.rb CASTE/LINES/ALTER/OFFER/KEEPS/HAVEN/SPEED/BASIC CASTE:0
    # ["LINES", "ALTER", "OFFER", "KEEPS", "SPEED"]
    # $ ruby fallout.rb CASTE/LINES/ALTER/OFFER/KEEPS/HAVEN/SPEED/BASIC
    # ["ALTER", "OFFER", "LINES", "SPEED", "BASIC", "KEEPS", "HAVEN", "CASTE"]
    # ```
    #
    # Next I guessed LINES, and the score was 1, so I ran this:
    # The program told me to pick "ALTER", so I did, and the terminal said the score
    # was 0, so I re-ran the program like this:
    #
    # ```
    # $ ruby fallout.rb CASTE/LINES/ALTER/OFFER/KEEPS/HAVEN/SPEED/BASIC CASTE:0/LINES:1
    # ["ALTER", "OFFER", "KEEPS", "SPEED"]
    # ```
    #
    # Next I guessed ALTER, and the score was 0, so I ran this:
    #
    # ```
    # $ ruby fallout.rb CASTE/LINES/ALTER/OFFER/KEEPS/HAVEN/SPEED/BASIC CASTE:0/LINES:1/ALTER:0
    # $ ruby fallout.rb CASTE/LINES/ALTER/OFFER/KEEPS/HAVEN/SPEED/BASIC ALTER:0/CASTE:0
    # ["KEEPS"]
    # ```
    #
    # The only choice left is "KEEPS", and it was the correct answer!

    def suggest list
    list.sort_by do |w1|
    ((list.length / 2) - list.count do |w2|
    w1 != w2 && w1.chars.zip(w2.chars).count { |a,b| a == b } > 0
    end).abs
    end
    end

    def hack w, t
    t.inject(w - t.map(&:first)) { |c, (w1, s)|
    suggest t.inject(w - t.map(&:first)) { |c, (w1, s)|
    c.find_all { |w2|
    s.to_i == w1.chars.zip(w2.chars).count { |a,b| a == b }
    }
    }
    end

    p hack ARGV[0].split('/'), ARGV[1].split('/').map { |x| x.split(':') }
    p hack ARGV[0].split('/'), (ARGV[1] || '').split('/').map { |x| x.split(':') }
  3. tenderlove revised this gist Nov 11, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions fallout.rb
    Original file line number Diff line number Diff line change
    @@ -44,11 +44,11 @@
    # The only choice left is "KEEPS", and it was the correct answer!

    def hack w, t
    t.inject(w-t.map(&:first)) { |c, (w1, s)|
    t.inject(w - t.map(&:first)) { |c, (w1, s)|
    c.find_all { |w2|
    s.to_i == w1.chars.zip(w2.chars).count { |a,b| a == b }
    }
    }
    end

    p hack ARGV[0].split('/'), ARGV[1].split('/').map { |x| x.split(':') }
    p hack ARGV[0].split('/'), ARGV[1].split('/').map { |x| x.split(':') }
  4. tenderlove revised this gist Nov 11, 2015. No changes.
  5. tenderlove revised this gist Nov 11, 2015. 1 changed file with 25 additions and 36 deletions.
    61 changes: 25 additions & 36 deletions fallout.rb
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,13 @@
    ##
    # Program to help you hack terminals in Fallout
    #
    # To use it, create a list of words shown in the terminal and pick one of them.
    # Usage:
    #
    # Make your first guess in the terminal, and it will give you a score. Then
    # run this program with a '/' separated list of possible words, and another
    # '/' separated list of words and scores where the word and score are separated
    # by a ':'
    #
    # In this example, the words shown in my terminal were:
    #
    # CASTE
    @@ -14,52 +20,35 @@
    # BASIC
    #
    # The first word I chose was "CASTE", and the terminal said it scored 0, so
    # I wrote this:
    #
    # ```ruby
    # words = %w{
    # CASTE
    # LINES
    # ALTER
    # OFFER
    # KEEPS
    # HAVEN
    # SPEED
    # BASIC
    # }
    # I ran this:
    #
    #
    # p hack words, [
    # ['CASTE', 0],
    # ]
    # ```
    # $ ruby fallout.rb CASTE/LINES/ALTER/OFFER/KEEPS/HAVEN/SPEED/BASIC CASTE:0
    # ["LINES", "ALTER", "OFFER", "KEEPS", "SPEED"]
    # ```
    #
    # The program output was:
    # Next I guessed LINES, and the score was 1, so I ran this:
    #
    # ```
    # [aaron@TC git]$ ruby fallout.rb
    # ["LINES", "ALTER", "OFFER", "KEEPS", "SPEED"]
    # $ ruby fallout.rb CASTE/LINES/ALTER/OFFER/KEEPS/HAVEN/SPEED/BASIC CASTE:0/LINES:1
    # ["ALTER", "OFFER", "KEEPS", "SPEED"]
    # ```
    #
    # Next, I tried "LINES", and the terminal said it was incorrect, but scored 1.
    # So I did this:
    # Next I guessed ALTER, and the score was 0, so I ran this:
    #
    # ```
    # p hack words, [
    # ['CASTE', 0],
    # ['LINES', 1],
    # ]
    # $ ruby fallout.rb CASTE/LINES/ALTER/OFFER/KEEPS/HAVEN/SPEED/BASIC CASTE:0/LINES:1/ALTER:0
    # ["KEEPS"]
    # ```
    #
    # Which output: ["ALTER", "OFFER", "KEEPS", "SPEED"]
    #
    # Next I tried "ALTER", and the terminal said 0, so I input that in the program,
    # and there was only one choice left, "KEEPS".
    # The only choice left is "KEEPS", and it was the correct answer!

    def hack words, tried
    tried.inject(words - tried.map(&:first)) { |c, (word1, score)|
    c.find_all { |word2|
    score == word1.chars.zip(word2.chars).count { |a,b| a == b }
    def hack w, t
    t.inject(w-t.map(&:first)) { |c, (w1, s)|
    c.find_all { |w2|
    s.to_i == w1.chars.zip(w2.chars).count { |a,b| a == b }
    }
    }
    end
    end

    p hack ARGV[0].split('/'), ARGV[1].split('/').map { |x| x.split(':') }
  6. tenderlove created this gist Nov 11, 2015.
    65 changes: 65 additions & 0 deletions fallout.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,65 @@
    ##
    # Program to help you hack terminals in Fallout
    #
    # To use it, create a list of words shown in the terminal and pick one of them.
    # In this example, the words shown in my terminal were:
    #
    # CASTE
    # LINES
    # ALTER
    # OFFER
    # KEEPS
    # HAVEN
    # SPEED
    # BASIC
    #
    # The first word I chose was "CASTE", and the terminal said it scored 0, so
    # I wrote this:
    #
    # ```ruby
    # words = %w{
    # CASTE
    # LINES
    # ALTER
    # OFFER
    # KEEPS
    # HAVEN
    # SPEED
    # BASIC
    # }
    #
    #
    # p hack words, [
    # ['CASTE', 0],
    # ]
    # ```
    #
    # The program output was:
    #
    # ```
    # [aaron@TC git]$ ruby fallout.rb
    # ["LINES", "ALTER", "OFFER", "KEEPS", "SPEED"]
    # ```
    #
    # Next, I tried "LINES", and the terminal said it was incorrect, but scored 1.
    # So I did this:
    #
    # ```
    # p hack words, [
    # ['CASTE', 0],
    # ['LINES', 1],
    # ]
    # ```
    #
    # Which output: ["ALTER", "OFFER", "KEEPS", "SPEED"]
    #
    # Next I tried "ALTER", and the terminal said 0, so I input that in the program,
    # and there was only one choice left, "KEEPS".

    def hack words, tried
    tried.inject(words - tried.map(&:first)) { |c, (word1, score)|
    c.find_all { |word2|
    score == word1.chars.zip(word2.chars).count { |a,b| a == b }
    }
    }
    end