adventofcode/2021/2/2.py

26 lines
740 B
Python
Raw Normal View History

2022-12-01 21:13:55 +01:00
#!/usr/bin/env python3
import re
def main():
position = { 'distance': 0, 'depth': 0, 'aim': 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['distance'] += amount
position['depth'] += position['aim'] * amount
elif direction == "down":
position['aim'] += amount
elif direction == "up":
position['aim'] -= amount
print(position['distance'] * position['depth'])
if __name__ == "__main__":
main()