From e8c84a0cb67a2ebbcf3aca048aa7cccc48291ba9 Mon Sep 17 00:00:00 2001 From: Xiretza Date: Thu, 2 Dec 2021 10:40:39 +0100 Subject: [PATCH] 2021 day2/python: add solution --- 2021/day2/day2.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 2021/day2/day2.py diff --git a/2021/day2/day2.py b/2021/day2/day2.py new file mode 100755 index 0000000..a2ad5d4 --- /dev/null +++ b/2021/day2/day2.py @@ -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)