Gamified challenge · Backtracking
maze is a list of equal-length strings: M is the mouse, C the cheese, # a wall and . a free tile. The mouse moves up, down, left or right onto free tiles and may never step on the same tile twice in one route. A route ends as soon as it reaches the cheese.
Write countRoutes(maze) (Python: count_routes(maze)) that returns how many different routes lead from M to C. Two routes are different if they visit different tiles or the same tiles in a different order. If the cheese can't be reached, return 0.
Example: in the open 3 × 3 room ["M..", "...", "..C"] there are 12 routes.
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