Skip to content

Instantly share code, notes, and snippets.

@loudambiance
Created December 16, 2021 04:13
Show Gist options
  • Save loudambiance/65ad5189229932fc764f313660732096 to your computer and use it in GitHub Desktop.
Save loudambiance/65ad5189229932fc764f313660732096 to your computer and use it in GitHub Desktop.
with open('task2a.txt') as f:
lines = f.read().splitlines()
x = 0
y = 0
aim = 0
for line in lines:
tmp = line.split(" ")
if tmp[0] == 'forward':
x = x + int(tmp[1])
y = y + (int(tmp[1]) * aim)
elif tmp[0] == 'up':
aim = aim - int(tmp[1])
elif tmp[0] == 'down':
aim = aim + int(tmp[1])
print (x*y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment