aoc
/
2022
1
0
Fork 0
2022/day02.rb

28 lines
446 B
Ruby
Raw Normal View History

2022-12-02 06:22:17 +00:00
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