diff options
Diffstat (limited to '2025/04/b.py')
| -rw-r--r-- | 2025/04/b.py | 26 |
1 files changed, 26 insertions, 0 deletions
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 @@ | |||
| 1 | import fileinput | ||
| 2 | |||
| 3 | def neigh(a, i, j): | ||
| 4 | return [ | ||
| 5 | a[i-1][j-1], a[i-1][j], a[i-1][j+1], | ||
| 6 | a[i][j-1], a[i][j+1], | ||
| 7 | a[i+1][j-1], a[i+1][j], a[i+1][j+1], | ||
| 8 | ].count('@') | ||
| 9 | |||
| 10 | s = 0 | ||
| 11 | with fileinput.input() as lines: | ||
| 12 | a = [['.'] * 200] | ||
| 13 | for line in lines: | ||
| 14 | a.append(['.'] + list(line.replace('\n', '.'))) | ||
| 15 | a.append(['.'] * 200) | ||
| 16 | |||
| 17 | rem = True | ||
| 18 | while rem: | ||
| 19 | rem = False | ||
| 20 | for i in range(1,len(a)-1): | ||
| 21 | for j in range(1,len(a[1])-1): | ||
| 22 | if a[i][j] == '@' and neigh(a, i, j) < 4: | ||
| 23 | s += 1 | ||
| 24 | rem = True | ||
| 25 | a[i][j] = '.' | ||
| 26 | print(s) | ||
