From 68615a9ad2c942254135cffb00cf25a84a3b1356 Mon Sep 17 00:00:00 2001 From: Prefetch Date: Sat, 31 Dec 2022 22:21:39 +0100 Subject: Initial commit --- 01/main.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 01/main.py (limited to '01/main.py') diff --git a/01/main.py b/01/main.py new file mode 100755 index 0000000..cd3ec34 --- /dev/null +++ b/01/main.py @@ -0,0 +1,35 @@ +#!/usr/bin/python + + + +def solve_partn(partn, data): + floor = 0 + for i, d in enumerate(data): + if d == "(": + floor += 1 + elif d == ")": + floor -= 1 + + if partn == 2: + if floor < 0: + return i + 1 + + if partn == 1: + return floor + else: # partn == 2 + return -1 # only reached if he never goes underground + + + +def main(): + # Read instructions from input text file + with open("input.txt", "r") as f: + data = f.read() + + print("Part 1 solution:", solve_partn(1, data)) # 74 for me + print("Part 2 solution:", solve_partn(2, data)) # 1795 for me + + + +if __name__ == "__main__": + main() -- cgit v1.2.3