Sep-27-2017, 04:57 PM
Imagine that the user specifies the width and height of a grid, as well as two tiles. You will return either "True" or "False" depending on whether or not the two tiles are neighbors by sharing at least one point. For example, on a 7x10 grid,
1 2 3 4 5 6 7
8
15
22 23 24 25 26 27 28
29 30
36
43
50
57
64
tiles 1 and 2 are neighbors. Tiles 24 and 30 are also neighbors.
A tile CANNOT be a neighbor of itself.
You may use the following formulas in your solution as needed:
row = (tile - 1) // width
col = (tile - 1) % width
1 2 3 4 5 6 7
8
15
22 23 24 25 26 27 28
29 30
36
43
50
57
64
tiles 1 and 2 are neighbors. Tiles 24 and 30 are also neighbors.
A tile CANNOT be a neighbor of itself.
You may use the following formulas in your solution as needed:
row = (tile - 1) // width
col = (tile - 1) % width