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