add: day04: part1
This commit is contained in:
29
2025/day04/part1.py
Normal file
29
2025/day04/part1.py
Normal file
@ -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)
|
||||
Reference in New Issue
Block a user