second day
This commit is contained in:
1 parent
bde5f0af82
commit
ce9790b20d
3 files changed
+1109
No files matched your search
Executable
+44
@@ -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")
|
||||
|
||||
Reference in new issue
Block a user