AoC 2019 D21: Springdroid Adventure
| Problem statement | Source code | Tags: IntcodePuzzle
← Previous Back to AoC Index Next →
Part 1
I have to say that I'm a bit annoyed by the vague wording. It took me a while to see that the jump distance is always 4. Still, there's a marvelous visualizer in this tiny program, so I shouldn't complain too much.
It turns out that there's no coding to do here. We just need to devise the logic, and then type it in. The observation is this: if we want to make a jump, both of these should be true: (1) the landing spot (D) must be ground, and (2) at least one of the next three spots (A, B, C) must be a hole, otherwise we should just walk. If A is a hole, we must jump; if B is a hole and A is ground, we actually may need to jump as well, because if "E" (can't see) is also a hole, we would have missed the chance. Similarly for C. So the logic is:
Turning this into instructions:
Part 2
I spent a while figuring out what the additional sensors are for. If I run the same logic as part 1, I get the following:
Indeed, at the final position, both A and D are holes, so we can't move. The problem looks like:
If we decide to jump at 0, then at 4, we won't be able to either jump or walk. To fix this, we need to ensure that either E or H is also ground when we jump. In conclusion:
In code:
Note that to calculate (E or H), we assume that T starts to be false. T was previously A and B and C; if that is true, then J is definitely false, so it's not a problem.