advent_of_code/2/2.py
kleph ba86d90e98
Some checks failed
continuous-integration/drone/push Build is failing
lint (W1514)
2022-04-05 13:56:34 +02:00

22 lines
487 B
Python
Executable file

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