day 2: quick maths
This commit is contained in:
parent
ba2a83de0c
commit
a6b5ccc5f3
2 changed files with 7 additions and 7 deletions
10
day02.py
10
day02.py
|
@ -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)
|
||||
|
|
4
day02.rb
4
day02.rb
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue