You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
740 B
Python

#!/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()