From 36bbb27ab186687a3a9b7b07e5ee6a4a13521ca9 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Sat, 9 Dec 2023 20:19:31 +0100 Subject: day 8 part 1 --- 08/main.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 08/main.py 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}") + -- cgit v1.2.3