adventofcode/2021/2/1.py

25 lines
639 B
Python
Raw Normal View History

2022-12-01 21:13:55 +01:00
#!/usr/bin/env python3
import re
def main():
position = { 'x': 0, 'y': 0 }
content = open('input', 'r').readlines()
for line in content:
move = line.strip()
match = re.match('^(\w+) (\d+)$', move)
direction, amount = match.groups(1)
amount = int(amount)
#print(f'logged: {direction} {amount} ')
if direction == "forward":
position['x'] += amount
elif direction == "down":
position['y'] += amount
elif direction == "up":
position['y'] -= amount
print(position['x'] * position['y'])
if __name__ == "__main__":
main()