Python Forum
Thread Rating:
  • 2 Vote(s) - 4.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Neighbors of a grid
#1
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
Reply


Messages In This Thread
Neighbors of a grid - by beatyjl - Sep-27-2017, 04:57 PM
RE: Neighbors of a grid - by ichabod801 - Sep-27-2017, 05:00 PM
RE: Neighbors of a grid - by nilamo - Sep-27-2017, 06:34 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Method of k-nearest neighbors qwerty 1 2,916 May-07-2017, 06:42 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020