From 33422840a980f68939ae1fab1ee015bf726574c0 Mon Sep 17 00:00:00 2001 From: Theis Date: Sun, 7 Dec 2025 14:10:08 +0100 Subject: [PATCH] Implement main logic for counting crossings and determining final position in the lock mechanism --- {Day 1/Part 1 => Day1/Part1}/input.txt | 0 {Day 1/Part 1 => Day1/Part1}/main.py | 0 {Day 1/Part 2 => Day1/Part2}/input.txt | 2 +- Day1/Part2/main.py | 32 ++++++++++++++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) rename {Day 1/Part 1 => Day1/Part1}/input.txt (100%) rename {Day 1/Part 1 => Day1/Part1}/main.py (100%) rename {Day 1/Part 2 => Day1/Part2}/input.txt (99%) create mode 100644 Day1/Part2/main.py diff --git a/Day 1/Part 1/input.txt b/Day1/Part1/input.txt similarity index 100% rename from Day 1/Part 1/input.txt rename to Day1/Part1/input.txt diff --git a/Day 1/Part 1/main.py b/Day1/Part1/main.py similarity index 100% rename from Day 1/Part 1/main.py rename to Day1/Part1/main.py diff --git a/Day 1/Part 2/input.txt b/Day1/Part2/input.txt similarity index 99% rename from Day 1/Part 2/input.txt rename to Day1/Part2/input.txt index 4d1f08f..39fbc72 100644 --- a/Day 1/Part 2/input.txt +++ b/Day1/Part2/input.txt @@ -4033,4 +4033,4 @@ R17 L19 R42 R48 -R39 +R39 \ No newline at end of file diff --git a/Day1/Part2/main.py b/Day1/Part2/main.py new file mode 100644 index 0000000..64cc5e8 --- /dev/null +++ b/Day1/Part2/main.py @@ -0,0 +1,32 @@ +def count_crossings_segment(P, delta): + P_new = P + delta + if delta > 0: + # positive Drehung: 100 * m in (P, P_new] + crossings = (P_new // 100) - (P // 100) + elif delta < 0: + # negative Drehung: 100 * m in [P_new, P-1] + crossings = ((P - 1) // 100) - ((P_new - 1) // 100) + else: + crossings = 0 + return crossings, P_new + +passes = 0 +P = 50 # „entfaltete“ Position, nicht mod 100! + +with open("input.txt", encoding="utf-8") as f: + for line in f: + line = line.strip() + if not line: + continue + + d = line[0].upper() + steps = int(line[1:]) + + delta = steps if d == 'R' else -steps + c, P = count_crossings_segment(P, delta) + passes += c + +final_pos = P % 100 + +print("Anzahl 0-PASSAGEN:", passes) +print("Endposition auf dem Schloss:", final_pos)