aboutsummaryrefslogtreecommitdiff
path: root/2025/04/b.py
blob: 93b1fffe576231b801fd8aa200ddc8abe9b7c3c1 (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
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('@')

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

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