Lane Marshal's Cursor Rover
Lane Marshal stress-tests cursor-control firmware with a one-dimensional rover that glides along a straight rail. The rail doubles as an editor ruler: the rover acts as the text cursor, and its job is to park exactly on a marked column named target.
The rover starts at position 0, faces the positive end of the rail, and moves with a speed of 1. The firmware exposes exactly two commands:
"A"(accelerate): the cursor advances by its current speed, so position becomesposition + speed, and the speed doubles (speed := speed * 2)."R"(reverse): the cursor holds its position, flips direction, and resets its stride to1. A positive speed becomes-1, and a negative speed becomes1(speed := speed > 0 ? -1 : 1).
For example, three consecutive accelerations carry the rover across 1 + 2 + 4 = 7 columns and leave it with speed 8. Gliding past the mark does not count as success: after the final command the cursor must stand exactly on target, facing either direction, moving at any speed.
Return the minimum number of commands needed to park the rover exactly on target.
Lane Marshal's Cursor Rover
Lane Marshal stress-tests cursor-control firmware with a one-dimensional rover that glides along a straight rail. The rail doubles as an editor ruler: the rover acts as the text cursor, and its job is to park exactly on a marked column named `target`.