Gamified challenge · Grid graphs
Water pours in from the left edge into the top-left tile and has to leave through the right edge of the bottom-right tile. Each tile is drawn at rotation 0: I opens up and down, L up and right, T left, up and right, + all four ways, and . is empty. Rotation k turns a tile k × 90° clockwise. Two neighbouring tiles connect only if both open toward each other.
Write rotations(grid) that returns a rotation from 0 to 3 for every tile, in a grid the same shape as grid, so the water gets through. For ["ILT", ".IL", "+LI"], turning the top-left I once makes it lie on its side, ready to take the water in: [[1, 2, 0], [0, 0, 0], [0, 0, 1]] works.
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