A question about example in day9: :thread:
# advent-of-code
j
A question about example in day9: 🧵
why, when going up, next step from
Copy code
......
....H.
....1.
.432..
5.....
is
Copy code
....H.
....1.
..432.
.5....
6.....
and not
Copy code
.....H.
.....1.
....2..
..43...
.5.....
? Why it’s not enough to move just
2
up?
c
Each knot is evaluated in rope order. So 1 is moved, then 2 is left diagonal, and must be moved diagonal. When 2 moves, 3 is left diagonal, and so must also move diagonal.
It might help to draw it out on paper, one step at a time.
r
The instructions say "if the head and tail aren't touching and aren't in the same row or column, the tail always moves one step diagonally to keep up". This is why 2 goes diagonally after 1 does its move.
j
@rkechols thanks. so my solution in part 1 worked without taking extra care of this condition, and when doing part 2, I haven’t re-read back all the part 1 Lesson learned 🙂
g
is this correct? I think in this example 2 doesn't have to move at all, as it still "touches" 1
j
if
H
goes up, then
1
follows and “disconnects” from
2
. So
2
needs to follow as well. In my solution, that worked for part 1, the next knot just entered the place previously occupied by the preceding knot. That was wrong for part 2. Then I thought “if it disconnects it should follow the movement of preceding knot”, that was wrong too. Correct solution is “if it disconnects, it should move towards new position of preceding knot”
c
My 2nd part was too low and it worked with the sample resulting in exactly the same output. So I had tried a completely different approach and eventually got it working. The difference was 2 more than the failed attempt. 🤷
c
Part 2 is nasty in that it brings up a situation that didn’t occur in Part 1 namely a knot being moved diagonally away from a knot it was already diagonal to leaving you 2 steps away diagonally.
Whilst the samples didn’t cover it directly the text
the tail always moves one step diagonally to keep up
covers it
e
Eric was kind enough to put in a
However, be careful: more types of motion are possible than before
warning in the text. too bad I didn't see it until after I discovered the issue myself 😅
c
Haha after re-reading it I still hadn’t spotted that
a
I had assumed that a > 1 difference might occur while doing part 1, and after doing part 2 was considering removing that. but now that I see others have had problems, I'm glad I didn't try to refactor it 🙃
r
Just confirming - for part 2, the answer is sum of all tails or just the tail 9?
c
Part 2 is just the tail not the intermediate knots.
r
I think i need to look at my approach again, for part 2 - it gives correct result for testInput and but fails for input. I took a static gird of enough size and performed movement in the grid.
c
I started with that approach and then changed to just record the positions and allowing for positive or negative coordinates. The it was also easy to reduce the movement rules to a simple expression.
r
I wasted time today with that approach and also in debugging why test input passed and actual didn't. Problem was grid size, i dropped the idea and went with just tracking the positions as you said.