From bc79fa83d3cb63d8445312b47dbed9295809b28a Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Thu, 4 Dec 2025 06:34:16 +0100 Subject: Day 4 2025 --- 2025/04/b.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 2025/04/b.py (limited to '2025/04/b.py') diff --git a/2025/04/b.py b/2025/04/b.py new file mode 100644 index 0000000..93b1fff --- /dev/null +++ b/2025/04/b.py @@ -0,0 +1,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) -- cgit v1.3