Skip to content

Commit

Permalink
Day 11: Plutonian Pebbles
Browse files Browse the repository at this point in the history
  • Loading branch information
ephemient committed Dec 11, 2024
1 parent 8b4384d commit 34c57b3
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ Development occurs in language-specific directories:
|[Day8.hs](hs/src/Day8.hs)|[Day8.kt](kt/aoc2024-lib/src/commonMain/kotlin/com/github/ephemient/aoc2024/Day8.kt)|[day8.py](py/aoc2024/day8.py)|[day8.rs](rs/src/day8.rs)|
|[Day9.hs](hs/src/Day9.hs)|[Day9.kt](kt/aoc2024-lib/src/commonMain/kotlin/com/github/ephemient/aoc2024/Day9.kt)|[day9.py](py/aoc2024/day9.py)|[day9.rs](rs/src/day9.rs)|
|[Day10.hs](hs/src/Day10.hs)|[Day10.kt](kt/aoc2024-lib/src/commonMain/kotlin/com/github/ephemient/aoc2024/Day10.kt)|[day10.py](py/aoc2024/day10.py)|[day10.rs](rs/src/day10.rs)|
|[Day11.hs](hs/src/Day11.hs)|[Day11.kt](kt/aoc2024-lib/src/commonMain/kotlin/com/github/ephemient/aoc2024/Day11.kt)|||
|[Day11.hs](hs/src/Day11.hs)|[Day11.kt](kt/aoc2024-lib/src/commonMain/kotlin/com/github/ephemient/aoc2024/Day11.kt)|[day11.py](py/aoc2024/day11.py)||
42 changes: 42 additions & 0 deletions py/aoc2024/day11.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""
Day 11: Plutonian Pebbles
"""

from collections import Counter


def part1(data: str) -> int:
return _solve(data, 25)


def part2(data: str) -> int:
return _solve(data, 75)


def _solve(data: str, n: int) -> int:
"""
>>> _solve("0 1 10 99 999", 1)
7
>>> _solve("125 17", 6)
22
>>> _solve("125 17", 25)
55312
"""
counts = Counter(map(int, data.split()))
for i in range(n):
next = Counter()
for num, count in counts.items():
if num == 0:
next[1] += count
else:
string = str(num)
if len(string) % 2 == 0:
next[int(string[: len(string) // 2])] += count
next[int(string[len(string) // 2 :])] += count
else:
next[2024 * num] += count
counts = next
return counts.total()


parts = (part1, part2)
1 change: 1 addition & 0 deletions py/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ day7 = "aoc2024.day7:parts"
day8 = "aoc2024.day8:parts"
day9 = "aoc2024.day9:parts"
day10 = "aoc2024.day10:parts"
day11 = "aoc2024.day11:parts"

[build-system]
requires = ["poetry-core"]
Expand Down

0 comments on commit 34c57b3

Please sign in to comment.