1
0
Fork 0

day 2: quick maths

This commit is contained in:
Sijmen 2022-12-04 11:17:00 +01:00
parent ba2a83de0c
commit a6b5ccc5f3
Signed by: vijfhoek
GPG key ID: DAF7821E067D9C48
2 changed files with 7 additions and 7 deletions

View file

@ -2,11 +2,11 @@ import fileinput
part1, part2 = 0, 0
for line in fileinput.input():
theirs = ord(line[0]) - ord('A')
ours = ord(line[2]) - ord('X')
for line in fileinput.input(mode='rb'):
theirs = line[0] - ord('A')
ours = line[2] - ord('X')
part1 += ours + (4, 7, 1)[(ours - theirs) % 3]
part2 += (1, 4, 7)[ours] + (theirs + ours - 1) % 3
part1 += ours + (ours - theirs + 1) % 3 * 3 + 1
part2 += ours * 3 + (theirs + ours - 1) % 3 + 1
print(part1, part2)

View file

@ -5,8 +5,8 @@ lines.each do |line|
theirs = line[0].ord - 'A'.ord
ours = line[2].ord - 'X'.ord
part1 += ours + [4, 7, 1][(ours - theirs) % 3]
part2 += [1, 4, 7][ours] + (theirs + ours - 1) % 3
part1 += ours + (ours - theirs + 1) % 3 * 3 + 1
part2 += ours * 3 + (theirs + ours - 1) % 3 + 1
end
puts part1, part2