Gamified challenge · Asked in Capgemini
A ball sits on a board with walls and movable blocks, and it has to reach the hole. Each row of board uses # for a wall, . for an empty cell, B for the ball, H for the hole and X for a block. One move slides one piece (the ball or a block) one cell up, down, left or right into an empty cell; only the ball may enter the hole.
Write solve(board) that returns the fewest moves that get the ball into the hole, each as "r c D": the piece's row and column (from 0) before it moves, then U, D, L or R. For ["#H#", "#X.", "#B#"] that's ["1 1 R", "2 1 U", "1 1 U"]: push the block aside, then roll up twice.
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