import util from collections import namedtuple input = util.get_input("2.input") State = namedtuple('State', ['x', 'y', 'aim']) def run(ops): state = State(0, 0, 0) for line in input: [op, arg] = line.split(' ') op = ops[op] state = op(state, int(arg)) return state ops = { 'up': lambda s, a: State(s.x, s.y - a, 0), 'down': lambda s, a: State(s.x, s.y + a, 0), 'forward': lambda s, a: State(s.x + a, s.y, 0), } state = run(ops) print(state.x * state.y) ops = { 'up': lambda s, a: State(s.x, s.y, s.aim - a), 'down': lambda s, a: State(s.x, s.y, s.aim + a), 'forward': lambda s, a: State(s.x + a, s.y + a * s.aim, s.aim), } state = run(ops) print(state.x * state.y)