# 2024 Day 11: Plutonian Pebbles

**URL:** <https://forum.ada-lang.io/t/2024-day-11-plutonian-pebbles/1578>\
**Category:** Advent of Code\
**Created:** [December 11, 2024, 8:54am UTC](https://forum.ada-lang.io/t/2024-day-11-plutonian-pebbles/1578 "2024-12-11T08:54:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JeremyGrosser](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/jeremygrosser/32/3_2.png) [@JeremyGrosser](https://forum.ada-lang.io/u/JeremyGrosser)\
**Post date:** [December 11, 2024, 8:54am UTC](https://forum.ada-lang.io/t/2024-day-11-plutonian-pebbles/1578/1 "2024-12-11T08:54:34Z")

</div>

Part 1, no problem. Part 2… Ended up being a complete rewrite. Once again, recursion is giving me a headache.

---

<div class="post-metadata">

**Author:** ![jcmoyer](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/jcmoyer/32/373_2.png) [@jcmoyer](https://forum.ada-lang.io/u/jcmoyer)\
**Post date:** [December 11, 2024, 3:38pm UTC](https://forum.ada-lang.io/t/2024-day-11-plutonian-pebbles/1578/2 "2024-12-11T15:38:01Z")

</div>

I’m impressed that you found a recursive solution. I started down a similar path initially but viewing it more like an automata problem where the simulation might eventually add a patterned number of stones every step. I couldn’t find any obvious patterns though so I looked at other properties of the input and fell into the (probably) more common solution of compressing the state and simulating large numbers of stones simultaneously instead. I think we’ve had nearly identical optimization problems in past years.

---

<div class="post-metadata">

**Author:** ![cantanima](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/cantanima/32/121_2.png) [@cantanima](https://forum.ada-lang.io/u/cantanima)\
**Post date:** [December 15, 2024, 4:57am UTC](https://forum.ada-lang.io/t/2024-day-11-plutonian-pebbles/1578/3 "2024-12-15T04:57:47Z")

</div>

Nice to see I’m not the only one who lost time trying to recurse. It turns out there are some very nice recursive solutions (the Reddit solutions use a cached DFS; one solution I examined caches the stone number and the depth at whcih it was found).

If I understand what @jcmoyer means by “compressing the state and simulating large numbers of stones” then I think he and I did the same thing. I’d phrase it as, I tracked the numbers on the stones with the numbers of those stones; so that the list `4 0 4 8 2 0 2 4` is instead the mapping `0 ↦ 2, 2 ↦ 2, 4 ↦ 3, 8 ↦ 1`.

---

<div class="post-metadata">

**Author:** ![alexispaez](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/alexispaez/32/920_2.png) [@alexispaez](https://forum.ada-lang.io/u/alexispaez)\
**Post date:** [January 2, 2025, 12:56pm UTC](https://forum.ada-lang.io/t/2024-day-11-plutonian-pebbles/1578/4 "2025-01-02T12:56:40Z")

</div>

Part 1 was easy, with a couple of vectors and an (naive I guess) iterative approach it solves in 0.48s, but the same approach with 75 blinks ends up eating the whole heap and failing, so obviously some optimization is needed 😅. What do you mean when you say “compress the state”?
