53 lines
1.6 KiB
Python
53 lines
1.6 KiB
Python
import numpy as np
|
|
|
|
count = 0
|
|
|
|
rolls = np.array([])
|
|
|
|
#
|
|
# I would like to thoroughly apologize for this monstrosity.
|
|
# I impore you, do not let this define your opinion of me.
|
|
# But I will understand if it does.
|
|
# Thank you for your attention in this matter.
|
|
#
|
|
|
|
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))
|
|
pass_count = -1
|
|
while pass_count != 0:
|
|
pass_count = 0
|
|
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:
|
|
if rolls[ni][nj] != 0:
|
|
adj_count += 1
|
|
|
|
if adj_count < 4:
|
|
count += 1
|
|
pass_count += 1
|
|
rolls[i][j] = 2
|
|
|
|
for i in range(lines_num):
|
|
for j in range(cols_num):
|
|
if rolls[i][j] == 2:
|
|
rolls[i][j] = 0
|
|
|
|
print(count) |