8
votes
Day 13: Point of Incidence
Today's problem description: https://adventofcode.com/2023/day/13
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>
Was glad for the break after how hard yesterday was (I wasn't able to solve part 2 yesterday, unfortunately, which is why I didn't post my solution). I could probably optimize this quite a bit further, but I don't really see the need to; it's plenty fast enough as it is. Hopefully the difficulty is a bit more consistent from here on out.
Solution
Golang solution
After yesterday's debacle, I had my best finish yet, just missing the top 2k. This one was pleasing in all aspects, and I'm happy with several of the optimizations in my solution.
Discussion
I found it simplest to transpose the pattern and just a have a row-oriented algorithm. Using a row of strings as a data structure made part 1 really easy, and since the patterns are pretty small, feasible for part 2. The main trick for Part 2 is that it is just part 1 but with the cumulative number of differences bounded to 1 instead of exact equality.
I wrote a generic
Grid
class the day before yesterday, and was looking forward to using it today! Unfortunately (and perhaps not unexpectedly) this made my life a bit harder because I'm locking myself into a complex data structure, and if I'm missing utility functions I need that makes my life harder, not easier.Part 1 comments
At first I wasted some time on this because I tried to compare the array index locations, then I realized "oh yeah I can just use startswith" and it was super easy all of a sudden. Although, I still ran into a slight snag because I didn't remember that this is actually super order-sensitive as to which one you reverse; so I had to fix that. Then I arrived on the solution.Part 2 discussion
One of the easiest day 2s due to how I solved day 1; all I did was to check when a row/col is "valid" in n-1 sets instead of all n.Python solutions
PHP! Ah, I haven't wrote anything in PHP probably since 6 years ago. I believe one of my largest (almost) solo project was in PHP in last year of high school. Next year my work is sending me to oversee a PHP shop, so I probably have to exercise it at some point.
Good thing this problem doesn't require array juggling so much, as I never wrote map/reduce in PHP. MY transpose algorithm allocate 2D array members out of nowhere, I'm surprised that it works. However, the resulting data type is not
array<char>
or evenarray<array<char>>
. It gave memap<int, string>
and iteration is done in insertion order, not by key. Luckilyksort
allow me to iterate by key order easily without fixing the data type.