Created
June 20, 2016 18:16
-
-
Save ctrombley/6191df51cf2da1f757f1e7e5edde0670 to your computer and use it in GitHub Desktop.
languages.rb
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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment