Python Forum

Full Version: Mirror of a grid
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Imagine that the user specifies with width and height of a grid, and a tile in that grid. Find the "mirror-mirror" of that tile, that is, if you folded the grid in half, and then folded it in half again, the tile that the original tile overlaps is its mirror-mirror (think of folding a sheet of paper in half, and then folding it in half again along the other axis). For example, for a 7x10 grid:

1 2 3 4 5 6 7
8 9 14
15 16
22 23 24 25 26 27 28
29 32
36 40
43 44 48
50 56
57 63
64 65 66 67 68 69 70

the mirror-mirror of tile 27 would be tile 44.

You may use the following formulas in your solution as needed:

row = (tile - 1) // width

column = (tile - 1) % width
Ok?

What have you tried so far?
I don't know where to start with this one
Start with the simplest possible problem, and slowly build on that until it matches the requirements.  For this, let's start with a 2x2 grid always.  Once you can solve for that, make sure it can solve for 3x3.  After THAT, let the user tell you how big the grid is, and make sure it still works.

>>> grid = [[0, 1], [2, 3]]
>>> # now what...?
...
Very similar, for others reading: https://python-forum.io/Thread-Neighbors-of-a-grid