diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-12-04 06:34:16 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-12-04 06:34:16 +0100 |
| commit | bc79fa83d3cb63d8445312b47dbed9295809b28a (patch) | |
| tree | 31302da9489e25df417d3ffd88c6f69a8ccf2745 /2025/04/a.py | |
| parent | 31c9f59a5f8946e8d90f2aad96e065ab4b496b67 (diff) | |
| download | aoc-bc79fa83d3cb63d8445312b47dbed9295809b28a.tar.gz aoc-bc79fa83d3cb63d8445312b47dbed9295809b28a.zip | |
Day 4 2025
Diffstat (limited to '2025/04/a.py')
| -rw-r--r-- | 2025/04/a.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/2025/04/a.py b/2025/04/a.py index 5fdb11b..a693841 100644 --- a/2025/04/a.py +++ b/2025/04/a.py | |||
| @@ -1,6 +1,21 @@ | |||
| 1 | import fileinput | 1 | import fileinput |
| 2 | 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 | ||
| 3 | with fileinput.input() as lines: | 11 | with fileinput.input() as lines: |
| 12 | a = [['.'] * 200] | ||
| 4 | for line in lines: | 13 | for line in lines: |
| 5 | ... | 14 | a.append(['.'] + list(line.replace('\n', '.'))) |
| 15 | a.append(['.'] * 200) | ||
| 6 | 16 | ||
| 17 | for i in range(1,len(a)-1): | ||
| 18 | for j in range(1,len(a[1])-1): | ||
| 19 | if a[i][j] == '@' and neigh(a, i, j) < 4: | ||
| 20 | s += 1 | ||
| 21 | print(s) | ||
