second day

This commit is contained in:
Maya Herrscher committed 2021-12-02 14:43:41 +01:00
1 parent bde5f0af82
commit ce9790b20d
3 files changed
+1109

No files matched your search

+44
View File
@@ -0,0 +1,44 @@
#!/usr/bin/env python3
import sys
if __name__ == '__main__':
lines = open(sys.argv[1]).readlines()
dirs = [i.strip('\n').split(" ") for i in lines]
# challenge 1
dep = 0
pos = 0
for d in dirs:
if d[0] == 'forward':
pos += int(d[1])
elif d[0] == 'up':
dep -= int(d[1])
elif d[0] == 'down':
dep += int(d[1])
else:
print(d)
res1 = str(dep * pos)
print("challenge 1:" + res1 + "\n")
# challenge 2
dep = 0
pos = 0
aim = 0
for d in dirs:
if d[0] == 'forward':
pos += int(d[1])
dep += int(d[1]) * aim
elif d[0] == 'up':
aim -= int(d[1])
elif d[0] == 'down':
aim += int(d[1])
else:
print(d)
res2 = str(dep * pos)
print("challenge 2:" + res2 + "\n")