Skip to content

Instantly share code, notes, and snippets.

@ackintosh
Created August 23, 2013 10:08
Show Gist options
  • Save ackintosh/6317673 to your computer and use it in GitHub Desktop.
Save ackintosh/6317673 to your computer and use it in GitHub Desktop.
LL QUIZ
require 'pry'
require 'test/unit'
class String
def ll_quiz
input = self.dup
output = ''
input.split("\n").each do |line|
target, strings = line.split(' ')
output += strings.split('').inject('') do |out, char|
out += (char == target) ? '*' : ' '
end
output += "\n"
end
output
end
end
class StringTest < Test::Unit::TestCase
def test_ll_quiz
input = <<'EOS'
1 919
2 992
3 399
EOS
expect = <<'EOS'
*
*
*
EOS
assert_equal(expect, input.ll_quiz)
end
end
input = <<'EOS'
1 222222222222
2 145681298690
3 212124345678
1 234567189876
4 343333433334
7 472226769067
9 592226968069
5 652222566665
4 744444444444
3 876542124567
EOS
puts input.ll_quiz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment