From 37cf0c9e7e14884760305da18fa74de61bd321e7 Mon Sep 17 00:00:00 2001 From: Reiko Kaps Date: Thu, 2 Dec 2021 08:13:01 +0100 Subject: [PATCH] =?UTF-8?q?Der=20L=C3=B6sung=20erster=20Teil?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2021/02/part-001.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) mode change 100644 => 100755 2021/02/part-001.py diff --git a/2021/02/part-001.py b/2021/02/part-001.py old mode 100644 new mode 100755 index a8f7375..37cda8a --- a/2021/02/part-001.py +++ b/2021/02/part-001.py @@ -1,3 +1,25 @@ #!/usr/bin/env python3 -with + +# start position +forward = 0 +depth = 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) + elif command == 'down': + depth = depth - int(value) + elif command == 'up': + depth = depth + int(value) + + +print('forward: {} depth: {}'.format(forward, depth)) +print('Submit value: {}'.format(forward * abs(depth))) + + +