Created
December 16, 2021 04:13
-
-
Save loudambiance/65ad5189229932fc764f313660732096 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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