Skip to content

Instantly share code, notes, and snippets.

@ajosanchez
Last active December 16, 2020 13:11

Revisions

  1. exchez revised this gist Nov 12, 2015. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions FO4_terminal_hack.rb
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    class Hack

    def initialize words
    @words = words.downcase.split(/\/|\s|,\s/)
    @words = words.downcase.split(/\/|\s|,\s|\,/)
    @splitwords = []
    @words.each { |w| @splitwords << w.split('') }
    show_likely
    @@ -37,7 +37,7 @@ def show_likely
    end

    def comb str
    hint = str.downcase.split('/')
    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
    @@ -68,4 +68,4 @@ def output
    puts "Input your word and likeness with a slash between (ex: foot/2) or quit to exit:"
    input = gets.chomp
    h.comb(input)
    end
    end
  2. exchez revised this gist Nov 12, 2015. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions FO4_terminal_hack.rb
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,4 @@

    class Hack
    attr_reader :match_matrix, :list

    def initialize words
    @words = words.downcase.split(/\/|\s|,\s/)
    @@ -70,4 +68,4 @@ def output
    puts "Input your word and likeness with a slash between (ex: foot/2) or quit to exit:"
    input = gets.chomp
    h.comb(input)
    end
    end
  3. exchez revised this gist Nov 12, 2015. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions FO4_terminal_hack.rb
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,9 @@

    class Hack
    attr_reader :match_matrix, :list

    def initialize words
    @words = words.downcase.split('/')
    @words = words.downcase.split(/\/|\s|,\s/)
    @splitwords = []
    @words.each { |w| @splitwords << w.split('') }
    show_likely
    @@ -42,8 +43,8 @@ def comb str
    @match_matrix.delete(hint[0])
    @match_matrix.each_value do |v|
    if v[hint[0]] != hint[1].to_i
    @match_matrix.delete(@match_matrix.key(v))
    @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])}
  4. exchez revised this gist Nov 12, 2015. 1 changed file with 11 additions and 6 deletions.
    17 changes: 11 additions & 6 deletions FO4_terminal_hack.rb
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    class Hack
    attr_reader :match_matrix, :list

    def initialize words
    @words = words.downcase.split('/')
    @@ -14,7 +15,8 @@ def deduct
    end
    end
    end



    def show_likely
    @match_matrix = {}
    @words.each do |w|
    @@ -34,34 +36,37 @@ def show_likely
    deduct
    output
    end

    def comb str
    hint = str.downcase.split('/')
    @match_matrix.delete(hint[0])
    @match_matrix.each_value do |v|
    if v[hint[0]] != hint[1].to_i
    @match_matrix.delete(@match_matrix.key(v))
    @match_matrix.each_value {|q| q.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.inject(0) {|sum, v| sum + v})-(k.length)} total matches"
    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 slash, no spaces (ex: dog/cat/hop)"
    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 guess and likeness with a slash between (ex: foot/2) or quit to exit:"
    puts "Input your word and likeness with a slash between (ex: foot/2) or quit to exit:"
    input = gets.chomp
    h.comb(input)
    end
    end
  5. exchez revised this gist Nov 11, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion FO4_terminal_hack.rb
    Original file line number Diff line number Diff line change
    @@ -61,7 +61,7 @@ def output
    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:"
    puts "Input your guess and likeness with a slash between (ex: foot/2) or quit to exit:"
    input = gets.chomp
    h.comb(input)
    end
  6. exchez revised this gist Nov 11, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion FO4_terminal_hack.rb
    Original file line number Diff line number Diff line change
    @@ -56,7 +56,7 @@ def output
    end
    end

    puts "enter list separated by a dash, no spaces (ex: dog/cat/hop)"
    puts "enter list separated by a slash, no spaces (ex: dog/cat/hop)"
    input = gets.chomp
    h = Hack.new(input)
    puts "\n"
  7. exchez revised this gist Nov 11, 2015. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions FO4_terminal_hack.rb
    Original file line number Diff line number Diff line change
    @@ -14,8 +14,7 @@ def deduct
    end
    end
    end



    def show_likely
    @match_matrix = {}
    @words.each do |w|
    @@ -35,7 +34,7 @@ def show_likely
    deduct
    output
    end

    def comb str
    hint = str.downcase.split('/')
    @match_matrix.delete(hint[0])
  8. exchez revised this gist Nov 11, 2015. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion FO4_terminal_hack.rb
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,4 @@
    class Hack
    attr_reader :match_matrix, :list

    def initialize words
    @words = words.downcase.split('/')
  9. exchez revised this gist Nov 11, 2015. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions FO4_terminal_hack.rb
    Original file line number Diff line number Diff line change
    @@ -4,10 +4,8 @@ class Hack
    def initialize words
    @words = words.downcase.split('/')
    @splitwords = []
    @words.each do { |w| @splitwords << w.split('') }
    end
    @words.each { |w| @splitwords << w.split('') }
    show_likely

    end

    def deduct
  10. exchez revised this gist Nov 11, 2015. 1 changed file with 1 addition and 6 deletions.
    7 changes: 1 addition & 6 deletions FO4_terminal_hack.rb
    Original file line number Diff line number Diff line change
    @@ -2,14 +2,9 @@ class Hack
    attr_reader :match_matrix, :list

    def initialize words
    @solutions = []
    @words = words.downcase.split('/')
    @splitwords = []
    @words.each do |w|
    @splitwords << w.split('')
    end
    @words.each do |w|
    @solutions << w
    @words.each do { |w| @splitwords << w.split('') }
    end
    show_likely

  11. exchez created this gist Nov 11, 2015.
    76 changes: 76 additions & 0 deletions FO4_terminal_hack.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,76 @@
    class Hack
    attr_reader :match_matrix, :list

    def initialize words
    @solutions = []
    @words = words.downcase.split('/')
    @splitwords = []
    @words.each do |w|
    @splitwords << w.split('')
    end
    @words.each do |w|
    @solutions << w
    end
    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('/')
    @match_matrix.delete(hint[0])
    @match_matrix.each_value do |v|
    if v[hint[0]] != hint[1].to_i
    @match_matrix.delete(@match_matrix.key(v))
    end
    end
    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.inject(0) {|sum, v| sum + v})-(k.length)} total 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