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.

25 lines
639 B
Python

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