35 lines
1006 B
Python
35 lines
1006 B
Python
import numpy as np
|
|
|
|
count = 0
|
|
|
|
rolls = np.array([])
|
|
|
|
with open('input.txt', 'r') as file:
|
|
cols_num = len(file.readline().strip())
|
|
file.seek(0)
|
|
lines_num = 0
|
|
for line in file:
|
|
for char in line.strip():
|
|
if char == '@':
|
|
rolls = np.append(rolls, 1)
|
|
else:
|
|
rolls = np.append(rolls, 0)
|
|
lines_num += 1
|
|
|
|
rolls = rolls.reshape((lines_num, cols_num))
|
|
for i in range(lines_num):
|
|
for j in range(cols_num):
|
|
if rolls[i][j] == 1:
|
|
adj_count = 0
|
|
for di in [-1, 0, 1]:
|
|
for dj in [-1, 0, 1]:
|
|
if di == 0 and dj == 0:
|
|
continue
|
|
ni, nj = i + di, j + dj
|
|
if 0 <= ni < lines_num and 0 <= nj < cols_num:
|
|
adj_count += rolls[ni][nj]
|
|
|
|
if adj_count < 4:
|
|
count += 1
|
|
|
|
print(count) |