Gamified challenge · Asked in Capgemini
A pattern of dots fills a rectangular grid: grid[r] is row r, where # is a dot and . is empty. Fold it over its vertical middle line and see whether the halves match; then fold it over its horizontal middle line.
Write symmetry(grid) that returns "vertical" if it mirrors left to right, "horizontal" if it mirrors top to bottom, "both" or "none". For ["#...#", ".#.#.", "..#.."] that's "vertical": every row reads the same backwards, but the top row isn't the bottom row.
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