pattern for finding neghboring sub squares in a grid.

31 Views Asked by At

I am a programmer working on some code, and I think I found a good way to solve a programming issue, but I'm too weak in math, so I need your help:

I have a grid, where I need to find all the opposing sides of any given square, which is what spawned this idea.

I have numbered all sides of the squares like this:

Grid

The middle square (not numbered in blue) is the one I need to find the opposing sides of.

By numbering the sides and corners like this all I need to do to find the opposinng side is to look at the number of that side/corner and go to the square with that number (in blue), and then take 10 minus the number I am looking up to find the side.

(examples circled in red)

A. opposing side of 1 = square with blue 1, side (10 - 1) = 9

B. opposing side of 6 = square with blue 6, side (10 - 6) = 4

C. opposing side of 8 = square with blue 8, side (10 - 8) = 2

That was the easy part.

Next part of the problem is what I need help with. I need to identify the numbers that are in the squares with blue text, that are neighboring to the opposing sides:

enter image description here

The sides were easy: the rule I came up with there was to add 1 to the number I am looking up and if the number is > 3 AND < 8 then I replace it with the opposing side number + 3.

A. opposing side of 2 = square with blue 2, side (10 - 2) = 8. Right hand neighbor of 8 = (8 + 1) = 9.

B. opposing side of 4 = square with blue 4, side (10 - 4) = 6. Right hand neighbor of 6 = (6 + 1) = 7...BUT (7 > 3 AND 7 < 8) so 7 is replaced with (6 + 3) = 9.

C. opposing side of 6 = square with blue 6, side (10 - 6) = 4. Right hand neighbor of 4 = (4 + 1) = 5...BUT (5 > 3 AND 5 < 8) so 5 is replaced with (4 + 3) = 7.

D. opposing side of 8 = square with blue 8, side (10 - 8) = 2. Right hand neighbor of 2 = (2 + 1) = 3.

I then do the same thing with the left hand side, but the rule is opposing side - 1, and if X < 7 && X > 2 then X = opposing side - 3

That takes care of all the sides, and now the corners is where I need help.

if we take 9:

opposing side of 9 = square with blue 9, side (10 - 9) = 1...

And that's where I am stuck. I need to work out what blue squares to look up numbers in(6 & 8) and I need to further find 2 & 3 in the square with a blue 8 and 4 & 7 in the square with a blue 6.

And I need to do so by only using the side that we look up and it's opposing side...and I just can't see the pattern.

I have noted the sequence as +1 + 3 -1 -3 for going right, and +3 -1 -3 +1 for going left like I did with the sides, but 1 and 9 complicates things as there are no squares named 0 & 10.

I did notice this relationship:

enter image description here

summing up to 4, 8, 12 & 16...but I don't know how/if that is relevant.

I hope this makes sense, I've tried to be as clear and descriptive as possible, but it's a complex problem, so if I need to clarify or give more examples then let me know an I will do so to the best of my ability. Thank you