advent_of_code/2/2_2.py
kleph 014a263cd1
Some checks failed
continuous-integration/drone/push Build is failing
Please linter a bit
2021-12-12 17:36:38 +01:00

24 lines
516 B
Python
Executable file

#!/usr/bin/env python
# 2021 - Advent Of Code - 2 part 2
import re
x = 0
y = 0
aim = 0
re_parse = re.compile(r'(forward|up|down) (\d+)')
with open('input.txt') as f:
for line in f:
m = re_parse.match(line)
direction, unit = m.group(1), int(m.group(2))
if direction == 'up':
aim -= unit
elif direction == 'down':
aim += unit
elif direction == 'forward':
x += unit
y += aim * unit
print(f'position: ({x}, {y}) => {x*y}')