From ec91d5c8246cbd9f5c7300be4a928bc41f3b2fd4 Mon Sep 17 00:00:00 2001 From: Reiko Kaps Date: Thu, 2 Dec 2021 09:25:11 +0100 Subject: [PATCH] Lesen hilft! --- 2021/02/part-002.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 2021/02/part-002.py diff --git a/2021/02/part-002.py b/2021/02/part-002.py new file mode 100755 index 0000000..9714ca6 --- /dev/null +++ b/2021/02/part-002.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 + + +# start position +forward = 0 +depth = 0 +aim = 0 + +with open('input.txt', 'r') as myfile: + for line in myfile: + # read file line by line + command, value = line.split(' ') + # print('command {} value {}'.format(command, value)) + if command == 'forward': + forward = forward + int(value) + if aim != 0: + depth = depth + (aim*int(value)) + + print('forward {} ... aim is {}'.format(int(value), aim)) + + elif command == 'down': + # depth = depth - int(value) + aim = aim + int(value) + + elif command == 'up': + # depth = depth + int(value) + aim = aim - int(value) + + +print('forward: {} depth: {}'.format(forward, depth)) +print('Submit value: {}'.format(forward * abs(depth))) + + +