2021 day2/python: add solution

This commit is contained in:
Xiretza 2021-12-02 10:40:39 +01:00
parent 1befbf9c37
commit e8c84a0cb6

20
2021/day2/day2.py Executable file
View file

@ -0,0 +1,20 @@
#!/usr/bin/env python
import sys
if __name__ == '__main__':
x = 0
y = 0
z = 0
for line in sys.stdin.readlines():
dir, amount = line.split()
amount = int(amount)
if dir == 'forward':
x += amount
z += y * amount
elif dir == 'down':
y += amount
elif dir == 'up':
y -= amount
print(x*y)
print(x*z)