From 3fb61d335f59ef4c1158d688b9b14cc4e26613bf Mon Sep 17 00:00:00 2001 From: FrederikBaerentsen Date: Fri, 8 Dec 2023 12:36:13 +0100 Subject: [PATCH] updated gitignore --- 2023/day8/p2.py | 47 ----------------------------------------------- 1 file changed, 47 deletions(-) delete mode 100644 2023/day8/p2.py diff --git a/2023/day8/p2.py b/2023/day8/p2.py deleted file mode 100644 index a229195..0000000 --- a/2023/day8/p2.py +++ /dev/null @@ -1,47 +0,0 @@ -from math import gcd -import sys - -steps, _, *rest = open(sys.argv[1]).read().splitlines() - -network = {} - -for line in rest: - pos, targets = line.split(" = ") - network[pos] = targets[1:-1].split(", ") - -positions = [key for key in network if key.endswith("A")] -cycles = [] - -for current in positions: - cycle = [] - - current_steps = steps - step_count = 0 - first_z = None - - while True: - print(current_steps) - while step_count == 0 or not current.endswith("Z"): - step_count += 1 - current = network[current][0 if current_steps[0] == "L" else 1] - print(current) - current_steps = current_steps[1:] + current_steps[0] - print(current_steps) - cycle.append(step_count) - - if first_z is None: - first_z = current - step_count = 0 - elif current == first_z: - break - - cycles.append(cycle) - -nums = [cycle[0] for cycle in cycles] - -lcm = nums.pop() - -for num in nums: - lcm = lcm * num // gcd(lcm, num) - -print(lcm)