1
0
Fork 0
This commit is contained in:
Sijmen 2022-12-02 07:22:17 +01:00
parent 2d6c252178
commit e9b71955f9
Signed by: vijfhoek
GPG key ID: DAF7821E067D9C48

27
day02.rb Normal file
View file

@ -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