Find a Repeating Vehicle Program Under Fuel and Memory Limits
WaymoSoftware Engineer · OnsiteLast updated
Find any repeating vehicle program of at most ten commands with fuel and obstacles, using complete bounded search, terminating simulation, and explicit execution assumptions.
Find a short program for a vehicle on a grid. The vehicle starts at a specified interior cell with 100 fuel units. It can move up, down, left, or right, spending one unit per move, or refuel at a station to gain 50 units. Obstacles cannot be crossed. The vehicle can store at most ten commands and repeats that same program until it reaches any cell in the final column.
Return any program that succeeds, or report that none exists under the stated rules. No shortest program or minimum number of moves is required.
Constraints & Assumptions
The source leaves execution details open. Use these explicit practice rules:
- Grid cells are free, blocked, or refueling stations. The supplied start is unblocked and not already in the last column. The map is finite and intended to be small enough for bounded-program search.
- Programs have length 1 through 10 over U, D, L, R, F. The instruction pointer wraps to zero after the last command.
- A move outside the grid, into an obstacle, or with zero fuel makes that candidate program fail. It does not cause the vehicle to wait or choose another direction.
- F is legal only at a refueling station, adds exactly 50 fuel, and does not move. No upper fuel capacity is imposed in this practice version because the source gives only initial fuel and refill amount.
- Reaching the last column succeeds immediately. A program that repeats forever without reaching it fails.
Clarifying Questions
Is the storage limit at most ten commands or exactly ten? Is fuel capacity capped? Are illegal moves fatal or ignored? Can a station be reused? Does the program have conditional branches?
Follow-up questions
- How would you prune invalid command prefixes or avoid equivalent repeated programs? Which additional constraints would justify a more sophisticated search? Why is ordinary shortest-path BFS insufficient when one fixed program must repeat?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.