Gamified challenge · BFS over states
A 3 × 3 tray holds tiles 1-8 and one gap, written 0. board[r][c] is the tile on row r, column c. A move slides a tile next to the gap into it, which is the same as moving the gap one step U, D, L or R (it can't leave the tray). The tray is sorted when it reads [[1,2,3],[4,5,6],[7,8,0]].
Write solve(board) that returns the gap's moves as a string, using the fewest moves possible (any shortest answer passes; return "" if it's already sorted). Half of all trays can never be sorted: for those, return "impossible".
Example: [[1,2,3],[4,0,6],[7,5,8]] → "DR": the gap moves down (tile 5 slides up), then right (tile 8 slides left).
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