aboutsummaryrefslogtreecommitdiff
path: root/2025/04/b.py
blob: 583c07652dff59e134e56ccf564e6e813d414b0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import fileinput

def neigh(a, i, j):
	return [
		a[i-1][j-1], a[i-1][j], a[i-1][j+1],
		a[i][j-1],              a[i][j+1],
		a[i+1][j-1], a[i+1][j], a[i+1][j+1],
	].count('@')

with fileinput.input() as lines:
	a = [
		['.'] * 200,
		*[['.'] + list(line.replace('\n', '.')) for line in lines],
		['.'] * 200,
	]

s = 0
rem = True
while rem:
	rem = False
	for i in range(1,len(a)-1):
		for j in range(1,len(a[1])-1):
			if a[i][j] == '@' and neigh(a, i, j) < 4:
				s += 1
				rem = True
				a[i][j] = '.'
print(s)

Generated with cgit - Back to sebastiano.tronto.net