Skip to content

Instantly share code, notes, and snippets.

@ctrombley
Created June 20, 2016 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ctrombley/88244a6245035b5bebf858a724b1bf07 to your computer and use it in GitHub Desktop.
Save ctrombley/88244a6245035b5bebf858a724b1bf07 to your computer and use it in GitHub Desktop.
languages.rb
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