I need to test a cell on a 2D grid/matrix to see if it's diagonal numbers have a power of 2 in them.
Example:
C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 R0: 00 01 02 03 04 05 06 07 08 09 R1: 10 11 12 13 14 15 16 17 18 19 R2: 20 21 22 23 24 25 26 27 28 29 R3: 30 31 32 33 34 35 36 37 38 39 R4: 40 41 42 43 44 45 46 47 48 49 R5: 50 51 52 53 54 55 56 57 58 59
The size of the grid is known. The values in each cell are simply ((R*W)+C) where:
- R=Row Number
- W=Width of Grid
- C=Column Number
Now let's pick two random cells:
- C3R4 = 43. Has diagonal values of (10, 21, 32, 54) & (07, 16, 25, 34, 52) out of which 16 and 32 are powers of 2.
- C8R1 = 18. Has no diagonal values that are powers of 2.
Required Result: f(x, y) = True or False.
Question:
- Is there a way to detect the above without looping?
- If this is not possible in a linear way, what would be the most efficient way to loop?