29 lines
575 B
Python
29 lines
575 B
Python
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) |