]> git.friedersdorff.com Git - max/advent_of_code_2021.git/commitdiff
Finish day 2
authorMaximilian Friedersdorff <max@friedersdorff.com>
Sat, 4 Dec 2021 22:03:06 +0000 (22:03 +0000)
committerMaximilian Friedersdorff <max@friedersdorff.com>
Sat, 4 Dec 2021 22:03:06 +0000 (22:03 +0000)
2_1.py [new file with mode: 0644]
2_2.py [new file with mode: 0644]

diff --git a/2_1.py b/2_1.py
new file mode 100644 (file)
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 (file)
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)