diff options
| -rw-r--r-- | 2025/04/a.py | 17 | ||||
| -rw-r--r-- | 2025/04/b.py | 26 | ||||
| -rw-r--r-- | 2025/README.md | 12 | ||||
| -rw-r--r-- | README.md | 2 |
4 files changed, 55 insertions, 2 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) | ||
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) | ||
diff --git a/2025/README.md b/2025/README.md index c72c8a5..8fccef4 100644 --- a/2025/README.md +++ b/2025/README.md | |||
| @@ -11,6 +11,7 @@ Example | |||
| 11 | 11 | ||
| 12 | ``` | 12 | ``` |
| 13 | Day -Part 1- -Part 2- | 13 | Day -Part 1- -Part 2- |
| 14 | 4 00:25:36 00:27:49 | ||
| 14 | 3 00:05:02 00:16:09 | 15 | 3 00:05:02 00:16:09 |
| 15 | 2 00:10:36 00:11:55 | 16 | 2 00:10:36 00:11:55 |
| 16 | 1 00:06:20 00:50:41 | 17 | 1 00:06:20 00:50:41 |
| @@ -49,3 +50,14 @@ For part 2 I used recursion with memorization (using Python's | |||
| 49 | `functools.cache`), which is fast enough. But later Chiara pointed | 50 | `functools.cache`), which is fast enough. But later Chiara pointed |
| 50 | out to me that actually the solution is quite trivially greedy; I | 51 | out to me that actually the solution is quite trivially greedy; I |
| 51 | implemented the greedy version in `b-alt.py`. | 52 | implemented the greedy version in `b-alt.py`. |
| 53 | |||
| 54 | ### Day 4: Printing Department | ||
| 55 | |||
| 56 | The first "map" problem of the year! This one was easy, but I | ||
| 57 | made a lot of mistakes in part 1. I decided to use the trick that | ||
| 58 | [Jared](https://guissmo.com) suggested a couple of years ago: extend the | ||
| 59 | map by 1 cell in all directions so you don't have to deal with indices | ||
| 60 | out of bounds. | ||
| 61 | |||
| 62 | For part 2 I decided to quickly code the dumb "repeat part 1 until no | ||
| 63 | rolls are removed" strategy and it worked. | ||
| @@ -14,4 +14,4 @@ See `year/README.md` for instructions on how to run my code. | |||
| 14 | |2022| 50 | Rust | Done in 2025 to learn Rust | | 14 | |2022| 50 | Rust | Done in 2025 to learn Rust | |
| 15 | |2023| 50 | C | All solved by December 25, 2023 | | 15 | |2023| 50 | C | All solved by December 25, 2023 | |
| 16 | |2024| 50 | C++ | Each solved within 24h | | 16 | |2024| 50 | C++ | Each solved within 24h | |
| 17 | |2025| 6 | Python | Work in progress... | | 17 | |2025| 8 | Python | Work in progress... | |
