From 957547756772bc00da9453d9aca35ba6fa06eaa9 Mon Sep 17 00:00:00 2001 From: Maximilian Friedersdorff Date: Sat, 4 Dec 2021 22:03:06 +0000 Subject: [PATCH] Finish day 2 --- 2_1.py | 19 +++++++++++++++++++ 2_2.py | 21 +++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 2_1.py create mode 100644 2_2.py diff --git a/2_1.py b/2_1.py new file mode 100644 index 0000000..4ad6f27 --- /dev/null +++ b/2_1.py @@ -0,0 +1,19 @@ +"""Calculate the final position of the submarine""" + +horizonal = 0 +depth = 0 +with open("2_1_input.txt") as f: + for line in f: + command, distance = line.split(" ") + distance = int(distance) + + if command == "down": + depth += distance + elif command == "up": + depth -= distance + elif command == "forward": + horizonal += distance + else: + raise RuntimeError("you fucked it captain") + +print(horizonal, depth, horizonal * depth) diff --git a/2_2.py b/2_2.py new file mode 100644 index 0000000..9c3b6a1 --- /dev/null +++ b/2_2.py @@ -0,0 +1,21 @@ +"""Calculate the final position of the submarine""" + +aim = 0 +horizonal = 0 +depth = 0 +with open("2_1_input.txt") as f: + for line in f: + command, distance = line.split(" ") + distance = int(distance) + + if command == "down": + aim += distance + elif command == "up": + aim -= distance + elif command == "forward": + horizonal += distance + depth += aim * distance + else: + raise RuntimeError("you fucked it captain") + +print(horizonal, depth, horizonal * depth) -- 2.46.2