5
votes
Day 14: Restroom Redoubt
Today's problem description: https://adventofcode.com/2024/day/14
Please post your solutions in your own top-level comment. Here's a template you can copy-paste into your comment to format it nicely, with the code collapsed by default inside an expandable section with syntax highlighting (you can replace python
with any of the "short names" listed in this page of supported languages):
<details>
<summary>Part 1</summary>
```python
Your code here.
```
</details>
Part 1 was straightforward calculation of (initial_position + velocity * time) % grid_size
For part 2 I kept track of how many horizontally adjacent robots there were at each time, figuring that the configuration with the Christmas tree would have the most of these. Fortunately that was correct. In a weak attempt to try to make it possible to work on anyone's input, I output the first time where there are at least 200 robots adjacent to each other in a horizontal direction.
Part 1 (Python)
Part 2 (Python)
Haha, this one was nice. Finally managed to get a rank below 1000 for part 2.
Part 1 (Rust)
Part 2 (Rust)
Just eyeball it.
I initially was ready to give up upon seeing part 2, because I thought I'd have to sit there and comb through an output log for ages to find the Christmas tree (which, in my opinion, would be a terrible puzzle). I eventually realized there's no way that would be the intended solution, so tried a few conditions before settling on "no robots on the same space". I'm still not really happy with this puzzle, though, since "in the shape of a Christmas tree" is incredibly vague, and my solution was just a guess - there could easily be a Christmas tree shape with multiple robots on the same tile, it just seemed like the puzzle wouldn't have been designed that way to me. I don't know. Probably my least favorite day so far, because it doesn't feel there's a "foolproof" solution. This puzzle seems to have been designed more to be cute than to be interesting to solve.
Solution (Jai)
That's an interesting way to do it -- it's also the fastest one among the several I tested after looking up how other people did this, running in 6-ish milliseconds. That no robot overlaps in the target image makes sense, because the puzzle input was likely generated by running the velocities in reverse, but to me it is not obvious why every other frame has at least one overlapping robot. I guess the input must have been prepared to specifically have this property.
As an aside, for something that seems like it needs manual inspection, there seem to be a lot of different ways to solve this automatically, from just checking for adjacent robots to working with entropies and robot spread variances. It's also possible to filter for the minimum safety scores from part 1 in order to find the tree, which seems like the intended way to do it.
Yeah, the speed at which it worked and how it did so with no issues was surprising, and suggests to me that the designer may have thought of that solution - though, what I did and checking for the minimum safety scores are somewhat similar solutions, so it's possible that my method works because the former was planned for. I can't say I'm very satisfied with myself for figuring it out, though, since it was just a hunch that I didn't really expect to work (as you said, it seems unlikely that it would do so without the input being specifically prepared for it). I think there's a good puzzle somewhere in here, but it just needed some extra clarification in my opinion.
Continuing to find more new tools that Pharo has built-in! Today was
quadrantOf:
which was helpful for part 1 andfourNeighbors
which I could have avoided writing myself in some previous days and helped for my approach to part 2.If I have time this weekend I might look a bit more into Morphs and how to set up some useful displays for future days. In the past I always just relied on ASCII displays, but Morphs seem to make generating simple visualizations very straightforward, so worth checking out.
Pharo Smalltalk Solution
Part 1 was easy (and I finally learned about structs in Racket!)
Part 2 I just stole the idea from lily's solution in here.
Racket
Wasn't sure how to approach part two, I first started looking for pixels that were symmetric across the y axis, but then I realized the image probably didn't need to be centered. Then I had the idea to try and measure the entropy of each pixel, once they were in the arrangement of a christmas tree that probably had low entropy. Super fun puzzle :)
Part 2