From 8a8568ad535425b612272a2f5b1b6f78747c90b3 Mon Sep 17 00:00:00 2001 From: Starnakin Date: Thu, 4 Dec 2025 11:57:33 +0100 Subject: [PATCH] add: day04: part1 --- 2025/day04/part1.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 2025/day04/part1.py diff --git a/2025/day04/part1.py b/2025/day04/part1.py new file mode 100644 index 0000000..cea2045 --- /dev/null +++ b/2025/day04/part1.py @@ -0,0 +1,29 @@ +text: str + +with open("input.txt") as f: + text = f.read() + +total: int = 0 + +def eval(lines: list[str], x: int, y: int): + start_x = max(x - 1, 0) + stop_x = min(len(lines[0]), x + 2) + start_y = max(y - 1, 0) + stop_y = min(len(lines[0]), y + 2) + + count: int = 0 + + for line in lines[start_y:stop_y]: + count += line[start_x:stop_x].count("@") + + return ((count - 1) < 4) + + +lines = text.splitlines() + +for y, line in enumerate(lines): + for x, c in enumerate(line): + if c == "@": + total += eval(lines, x, y) + +print(total) \ No newline at end of file