Part 1
In this puzzle, we have a grid with a continous line. The line only goes straight or turns by 90°. Along the line there are letters and we should find in which order the letters appear on the line.
We again save the current position and direction as a complex number, with the real part for the rows and the imaginary part for the columns. We can follow the current direction until we reach a junction point. We then check around this point which directions are now possible.
for newDirection in [1, -1, 1j, -1j]:
if valid_move(pos + newDirection):
direction = newDirection
Once we can only return to the position we just arrived from, we can stop.
Part 2
In part 2, we should also count the number of steps until the final letter.
For this, we introduced a variable increased every time we step in a direction.
No comments:
Post a Comment