Skip to content

Instantly share code, notes, and snippets.

@ctrombley
Created June 20, 2016 18:16
Show Gist options
  • Save ctrombley/88244a6245035b5bebf858a724b1bf07 to your computer and use it in GitHub Desktop.
Save ctrombley/88244a6245035b5bebf858a724b1bf07 to your computer and use it in GitHub Desktop.

Revisions

  1. ctrombley renamed this gist Jun 20, 2016. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. ctrombley created this gist Jun 20, 2016.
    29 changes: 29 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    require 'minitest/autorun'

    describe "LanguageSolver" do
    let (:solver) { LanguageSolver.new }
    it "should generate pairs for comparison" do
    solver.pairs(['ccda','ccbk', 'cd', 'a', 'ab', 'abd', 'aba'])
    .must_equal([['d','b'],['c','d'],['c','a'],['d','a']])
    end
    end

    class LanguageSolver
    def pairs(ary)
    pairs = []
    ary[1..-1].each_with_index do |word, i|
    puts
    (0...word.size).each do |j|
    puts "comparing #{ary[i-1][j]}, #{word[j]}"
    if ary[i-1][j] == word[j] || ary.size <= j
    next
    end
    puts "found difference"
    pairs << [ary[i-1][j], word[j]]
    break
    end
    end

    pairs
    end
    end