7
votes
Day 17: Set and Forget
Today's problem description: https://adventofcode.com/2019/day/17
Join the Tildes private leaderboard! You can do that on this page, by entering join code 730956-de85ce0c
.
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>
This was a funny one in that I almost ended up writing no new code to solve it. I already had a debugger that could handle ASCII input and output, I just had to tweak it a bit to make feeding lines with the newline character easier.
Since I didn't write much new code, I'll just share the bare-bones debugger I'm using:
Intcode Debugger - Crystal
Part 1
As mentioned, this was quite simple: I just loaded the program into my debugger, enabled ASCII output, and ran the program to get the map.Once I had the map, it wasn't difficult to just look for the intersections and manually compute the answer from their positions.
Part 2
Part 2 is a kind of simple compression problem: you have a single long string (the full path the robot needs to traverse), and you must break it down into three different repeated chunks.
Once again I was able to work out the path manually, and if you write out the steps it's not too difficult to find the repeating patterns. My editor helped a bit here since it was easy to try out substitutions by using the interactive search/replace feature.
I did get stuck here for a while because of a transcription error that meant that the path I was working with didn't break down into chunks the way it should've; if you take the manual approach be sure to double check your work!
Once I realized my error and could compress the path the way the robot wanted, I was able to just feed that back into the program in my debugger and get the answer.
Edit:
I still had an itch to write some more code, so I worked out an automated solution to P1 (edit-edit, also extracting the uncompressed path for p2):
Part 1 - Crystal