From: Maximilian Friedersdorff Date: Sat, 4 Dec 2021 22:03:06 +0000 (+0000) Subject: Finish day 2 X-Git-Url: https://git.friedersdorff.com/?a=commitdiff_plain;h=957547756772bc00da9453d9aca35ba6fa06eaa9;hp=b4fed13abe1b3438a7ab4bba762b47aecd85cd56;p=max%2Fadvent_of_code_2021.git Finish day 2 --- 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)