diff --git a/day02.rb b/day02.rb new file mode 100644 index 0000000..1db6e1a --- /dev/null +++ b/day02.rb @@ -0,0 +1,27 @@ +lines = STDIN.read.split("\n") + +part1 = 0 +part2 = 0 + +input = lines.map do |line| + theirs = line[0].ord - 'A'.ord + ours = line[2].ord - 'X'.ord + + part1 += ours + 1 + + if ours == theirs then + part1 += 3 + elsif (theirs + 1) % 3 == ours then + part1 += 6 + end + + if ours == 0 then + part2 += (theirs - 1) % 3 + 1 + elsif ours == 1 then + part2 += theirs + 3 + 1 + else + part2 += (theirs + 1) % 3 + 6 + 1 + end +end + +puts part1, part2