#!/usr/bin/env python3 # start position forward = 0 depth = 0 aim = 0 with open('input.txt', 'r') as myfile: for line in myfile: # read file line by line command, value = line.split(' ') # print('command {} value {}'.format(command, value)) if command == 'forward': forward = forward + int(value) if aim != 0: depth = depth + (aim*int(value)) print('forward {} ... aim is {}'.format(int(value), aim)) elif command == 'down': # depth = depth - int(value) aim = aim + int(value) elif command == 'up': # depth = depth + int(value) aim = aim - int(value) print('forward: {} depth: {}'.format(forward, depth)) print('Submit value: {}'.format(forward * abs(depth)))