wip: 2024/day10/part1
This commit is contained in:
parent
3aec98af5b
commit
5289db169b
39
2024/day10/part1.py
Normal file
39
2024/day10/part1.py
Normal file
@ -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)
|
Loading…
Reference in New Issue
Block a user