Question

I need to write a function that finds the successors of a given coordinate. By successors I mean, 3 kinds: horizontal, vertical and diagonal.

Horizontal its easy: match the row number of the coordinate to the row number of the next one and it is the horizontal successor of that coordinate.

Vertical: Same match the column number of the coordinate to the column number of the next one and that determines if its a vertical successor

Diagonal: Not sure. A square has only 2 digonals so if my coordinate is on the diagonal of the square, I need to verify this first, if it is then I need to find its successors. How do I do this?

 1) verify a point is on the diagonal of a square? and 
 2) If it is on the diagonal find its successor?

For example in this grid:

 00, 01, 02, 03, 04, 05, 06, 07, 08
 10, 11, 12, 13, 14, 15, 16, 17, 18
 20, 21, 22, 23, 24, 25, 26, 27, 28
 30, 31, 32, 33, 34, 35, 36, 37, 38
 40, 41, 42, 43, 44, 45, 46, 47, 48
 50, 51, 52, 53, 54, 55, 56, 57, 58
 60, 61, 62, 63, 64, 65, 66, 67, 68
 70, 71, 72, 73, 74, 75, 76, 77, 78
 80, 81, 82, 83, 84, 85, 86, 87, 88

Thanks

Was it helpful?

Solution

Find points on diagonals :-

if(i==j) {

left diagonal

} if(i==n-j-1) {

right diagonal

}

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top