From e9b71955f913129124b14e76f42c4d525b9d4237 Mon Sep 17 00:00:00 2001 From: Sijmen Date: Fri, 2 Dec 2022 07:22:17 +0100 Subject: [PATCH] day 2 --- day02.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 day02.rb 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