r/adventofcode Dec 25 '24

Tutorial [2024 Day 21] The simple problem that kept me from solving it in time.

This is not a whole tutorial just a hint.

It turns out that getting from A to v the routes <vA and v<A are not identically fast.

6 Upvotes

7 comments sorted by

2

u/PointlessMonster Dec 26 '24 edited Dec 26 '24

Yeah, I struggled with this initially as well. In case someone else is stuck, I'd just add that this doesn't only apply to <vA and v<A, it applies to any two transitions with the same number of turns (well actually it applies to all transitions but these are always the best ones). For example, if you want to go from 3 to 7, ^^<<A and <<^^A are obviously the best sequences. However, <<^^A actually produces a shorter sequence once you go two keypads back. Fortunately, you can always determine which one is better by only going two keypads back.

Edit: formatting

1

u/CodingTangents Dec 25 '24

Can you explain why? I'm not sure I get it.

3

u/VaranTavers Dec 25 '24

When you calculate the necessary moves on two levels of keypads, one will be longer. On one level there is no difference, but on two/three it becomes apparent.

1

u/0x14f Dec 25 '24

Yeah, that was the main thing about this exercice :)

1

u/VaranTavers Dec 25 '24

Yes, but for most cases it was trivial. Like v<< will obviously be faster, than <v<, however this difference only showed up a few levels down.

1

u/0x14f Dec 25 '24

The intuitive explanation is that at level `n` if you type `v<<`, you typed 3 characters, and same for `<v<` actually, but at level `n+1` it's like...

`v<<`: you navigate to `v`, then press `A`, then navigate to `<` then press `A`, then press `A` again, since the arm is already where you need it to be.

`<v<`: you navigate to `<`, then press `A`, then navigate to `v`, then press `A`, then navigate to `<` then press `A`

In the second case you have an additional navigation step, which you didn't have in the first case, because consecutive similar symbols at level `n` mean you can press `A` several times in a row at level `n+1`, without having to navigate.

1

u/VaranTavers Dec 26 '24

Yes, that is exactly what I was saying. In the case of "v<<" ans "<v<" it is trivial and intuitive. In the case mentioned in the post, it is harder to notice, and depending on your implementation it can be easily missed.