From 5289db169b44e24aaf4bf9da84522a4c32421880 Mon Sep 17 00:00:00 2001 From: Starnakin Date: Fri, 13 Dec 2024 12:19:28 +0100 Subject: [PATCH] wip: 2024/day10/part1 --- 2024/day10/part1.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 2024/day10/part1.py diff --git a/2024/day10/part1.py b/2024/day10/part1.py new file mode 100644 index 0000000..4d35974 --- /dev/null +++ b/2024/day10/part1.py @@ -0,0 +1,39 @@ +import math + +text: str + +with open("test.txt") as f: + text = f.read() + +lines: list[str] = text.splitlines() +lines: list[int] = [[int(value) if value != "." else 11 for value in line] for line in lines] + +print(lines) + +total: int = 0 + +def trailhead_tester(ground: list[int], pos_y: int, pos_x: int, ground_y: int, ground_x: int): + + if ground[pos_y][pos_x] == 9: + return 1 + + min_x: int = max(pos_x - 1, 0) + max_x: int = min(pos_x + 1, ground_x) + min_y: int = max(pos_y - 1, 0) + max_y: int = min(pos_y + 1, ground_y) + + for y, line in enumerate(ground[min_y:max_y]): + for x, value in enumerate(line[min_x:max_x]): + if ground[pos_y][pos_x] + 1 == value: + return trailhead_tester(ground, pos_y + (max_y - min_y) - 2, pos_x + (max_x - min_x) - 2, ground_x, ground_y) + return 0 + +y_max = len(lines) +x_max = len(lines[0]) + +for y, line in enumerate(lines): + for x, value in enumerate(line): + if (value == 0): + total += trailhead_tester(lines, y, x, y_max, x_max) + +print(total) \ No newline at end of file