Skip to content

Commit ef1ce5e

Browse files
committed
2024 day 11
1 parent f1f84e3 commit ef1ce5e

File tree

5 files changed

+51
-2
lines changed

5 files changed

+51
-2
lines changed

2024/python/data/day11/example.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
125 17

2024/python/data/day11/input.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
773 79858 0 71 213357 2937 1 3998391

2024/python/src/aoc2024/day11.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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)

2024/python/tests/test_day11.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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 -->

0 commit comments

Comments
 (0)