From ca39de904062636a0a9fe649b4be0cd1f697f136 Mon Sep 17 00:00:00 2001 From: starnakin Date: Fri, 8 Dec 2023 10:21:09 +0100 Subject: [PATCH] add: part1 --- 2023/day08/example1.txt | 9 +++++++++ 2023/day08/example2.txt | 5 +++++ 2023/day08/src/part1.py | 27 +++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 2023/day08/example1.txt create mode 100644 2023/day08/example2.txt create mode 100644 2023/day08/src/part1.py diff --git a/2023/day08/example1.txt b/2023/day08/example1.txt new file mode 100644 index 0000000..59e2d47 --- /dev/null +++ b/2023/day08/example1.txt @@ -0,0 +1,9 @@ +RL + +AAA = (BBB, CCC) +BBB = (DDD, EEE) +CCC = (ZZZ, GGG) +DDD = (DDD, DDD) +EEE = (EEE, EEE) +GGG = (GGG, GGG) +ZZZ = (ZZZ, ZZZ) \ No newline at end of file diff --git a/2023/day08/example2.txt b/2023/day08/example2.txt new file mode 100644 index 0000000..34ffa8a --- /dev/null +++ b/2023/day08/example2.txt @@ -0,0 +1,5 @@ +LLR + +AAA = (BBB, BBB) +BBB = (AAA, ZZZ) +ZZZ = (ZZZ, ZZZ) \ No newline at end of file diff --git a/2023/day08/src/part1.py b/2023/day08/src/part1.py new file mode 100644 index 0000000..d515926 --- /dev/null +++ b/2023/day08/src/part1.py @@ -0,0 +1,27 @@ +text: str = open("input.txt", "r").read() + +_value: int = 0 + +lines = text.splitlines() + +deplacements = lines[0] +ground = {} + +for line in lines[2:]: + data = line.split(" = ") + data[1] = data[1][1:9] + ground.update({data[0]: data[1].split(", ")}) + +def resolve(ground: dict, deplacements: str, start: str): + nb_deplacement = 0 + pos = start + while True: + for deplacement in deplacements: + if (pos == "ZZZ"): + return (nb_deplacement) + nb_deplacement += 1 + pos = ground.get(pos)[deplacement == "R"] + +_value = resolve(ground, deplacements, "AAA") + +print(_value) \ No newline at end of file