summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2023-12-09 20:19:31 +0100
committerlonkaars <loek@pipeframe.xyz>2023-12-09 20:19:31 +0100
commit36bbb27ab186687a3a9b7b07e5ee6a4a13521ca9 (patch)
treef13c02e9f8c59a96a63747bd6416ae969b6fbe52
parentbe634a34fc970139f6e9facb6f3af748a97ca535 (diff)
day 8 part 1
-rwxr-xr-x08/main.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/08/main.py b/08/main.py
new file mode 100755
index 0000000..bcbd2dd
--- /dev/null
+++ b/08/main.py
@@ -0,0 +1,27 @@
+#!/bin/python3
+import sys
+import re
+
+route = [("L", "R").index(x) for x in input().strip()]
+map = {}
+for line in sys.stdin:
+ line = line.strip()
+ if len(line) == 0: continue
+
+ line = re.sub("[^A-Z]+", " ", line)
+ location, left, right = line.split()
+
+ map[location] = (left, right,)
+
+START = "AAA"
+DESTINATION = "ZZZ"
+
+steps = 0
+current_location = START
+while current_location != DESTINATION:
+ route_idx = steps % len(route)
+ steps += 1
+ current_location = map[current_location][route[route_idx]]
+
+print(f">> {steps}")
+