Created
August 23, 2013 10:08
-
-
Save ackintosh/6317673 to your computer and use it in GitHub Desktop.
LL QUIZ
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 '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