File tree Expand file tree Collapse file tree 5 files changed +51
-2
lines changed
Expand file tree Collapse file tree 5 files changed +51
-2
lines changed Original file line number Diff line number Diff line change 1+ 125 17
Original file line number Diff line number Diff line change 1+ 773 79858 0 71 213357 2937 1 3998391
Original file line number Diff line number Diff line change 1+ import functools
2+ from pathlib import Path
3+
4+
5+ def part_1 (input : Path ) -> int :
6+ stones = list (map (int , input .read_text ().strip ().split ()))
7+ return sum (count_stones (stone , 25 ) for stone in stones )
8+
9+
10+ def part_2 (input : Path ) -> int :
11+ stones = list (map (int , input .read_text ().strip ().split ()))
12+ return sum (count_stones (stone , 75 ) for stone in stones )
13+
14+
15+ @functools .cache
16+ def count_stones (stone : int , blinks_remaining : int ) -> int :
17+ if blinks_remaining == 0 :
18+ return 1
19+
20+ if stone == 0 :
21+ return count_stones (1 , blinks_remaining - 1 )
22+
23+ str_stone = str (stone )
24+ if len (str_stone ) % 2 == 0 :
25+ return count_stones (
26+ int (str_stone [: len (str_stone ) // 2 ]),
27+ blinks_remaining - 1 ,
28+ ) + count_stones (
29+ int (str_stone [len (str_stone ) // 2 :]),
30+ blinks_remaining - 1 ,
31+ )
32+
33+ return count_stones (stone * 2024 , blinks_remaining - 1 )
Original file line number Diff line number Diff line change 1+ from pathlib import Path
2+
3+ from aoc2024 import day11
4+
5+ DATA_DIR = Path (__file__ ).parent .parent / "data/day11"
6+
7+
8+ def test_part_1 ():
9+ assert day11 .part_1 (DATA_DIR / "example.txt" ) == 55312
10+ assert day11 .part_1 (DATA_DIR / "input.txt" ) == 199982
11+
12+
13+ def test_part_2 ():
14+ assert day11 .part_2 (DATA_DIR / "input.txt" ) == 237149922829154
Original file line number Diff line number Diff line change @@ -18,8 +18,8 @@ Updated 2026-01-03.
1818| ** 2021** | ** 50/50**   ; 🌟 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 |
1919| ** 2022** | ** 50/50**   ; 🌟 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 |
2020| ** 2023** | 42/50 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | ⬜ | 🟩 | ⬜ | ⬜ | ⬜ |
21- | ** 2024** | 20 /50 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | ⬜ | ⬜ | ⬜ | ⬜ | ⬜ | ⬜ | ⬜ | ⬜ | ⬜ | ⬜ | ⬜ | ⬜ | ⬜ | ⬜ | ⬜ |
21+ | ** 2024** | 22 /50 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | ⬜ | ⬜ | ⬜ | ⬜ | ⬜ | ⬜ | ⬜ | ⬜ | ⬜ | ⬜ | ⬜ | ⬜ | ⬜ | ⬜ |
2222| ** 2025** | ** 24/24**   ; 🌟 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | 🟩 | ⬛ | ⬛ | ⬛ | ⬛ | ⬛ | ⬛ | ⬛ | ⬛ | ⬛ | ⬛ | ⬛ | ⬛ | ⬛ |
2323
24- Total stars: 334 /524
24+ Total stars: 336 /524
2525<!-- PROGRESS_END -->
You can’t perform that action at this time.
0 commit comments