Gamified challenge · BFS over states
lot is 6 strings of 6 characters: . is an empty space and each letter is one car (2 or 3 cells long, in a straight line). A car lying across a row only drives left and right; a car lying along a column only drives up and down. Car A is your red car, lying across its row; the exit is on the right edge of that row.
A move slides one car any number of cells along its lane, through empty spaces only, and is written "<car> <direction> <cells>", like "B U 1" or "A R 3". Write freeCar(lot) (Python: free_car(lot)) that returns the moves, as few as possible, after which A touches the right edge. Any shortest list passes; return [] if A is already there. Every lot can be solved.
Example: in ["......", "......", "AA..B.", "....B.", "......", "......"], car B blocks the way. Two moves are enough: ["B D 1", "A R 4"] (or ["B U 2", "A R 4"]).
This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.
Sign in with Google