summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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}")
+