I have a grid represented as follows...

01 02 03 04 05 06 07 08 09

10 11 12 13 14 15 16 17 18

19 20 21 22 23 24 25 26 27

28 29 30 31 32 33 34 35 36

37 38 39 40 41 42 43 44 45

46 47 48 49 50 51 52 53 54

55 56 57 58 59 60 61 62 63

64 65 66 67 68 69 70 71 72

73 74 75 76 77 78 79 80 81

I need a way to take any number between 1 and 81 and use that number as the basis for calculating what 'group' that number belongs to (groups named A..I). The groups are segmented as follows...

01 02 03 04 05 06 07 08 09

10 11 12 13 14 15 16 17 18

19 20 21 22 23 24 25 26 27

28 29 30 31 32 33 34 35 36

37 38 39 40 41 42 43 44 45

46 47 48 49 50 51 52 53 54

55 56 57 58 59 60 61 62 63

64 65 66 67 68 69 70 71 72

73 74 75 76 77 78 79 80 81

Once the group (for examples sake 'I') is known I need to determine the numbers that exist within its respective group. So for example...

#45 = GROUP F = 34,35,36,43,44,45,52,53,54

This can be achieved with a nasty switch statement I am sure, but I was hoping a more elegant solution might exist out there that uses some math formula?

Any ideas?

01 02 03 04 05 06 07 08 09

10 11 12 13 14 15 16 17 18

19 20 21 22 23 24 25 26 27

28 29 30 31 32 33 34 35 36

37 38 39 40 41 42 43 44 45

46 47 48 49 50 51 52 53 54

55 56 57 58 59 60 61 62 63

64 65 66 67 68 69 70 71 72

73 74 75 76 77 78 79 80 81

I need a way to take any number between 1 and 81 and use that number as the basis for calculating what 'group' that number belongs to (groups named A..I). The groups are segmented as follows...

01 02 03 04 05 06 07 08 09

10 11 12 13 14 15 16 17 18

19 20 21 22 23 24 25 26 27

28 29 30 31 32 33 34 35 36

37 38 39 40 41 42 43 44 45

46 47 48 49 50 51 52 53 54

55 56 57 58 59 60 61 62 63

64 65 66 67 68 69 70 71 72

73 74 75 76 77 78 79 80 81

Once the group (for examples sake 'I') is known I need to determine the numbers that exist within its respective group. So for example...

#45 = GROUP F = 34,35,36,43,44,45,52,53,54

This can be achieved with a nasty switch statement I am sure, but I was hoping a more elegant solution might exist out there that uses some math formula?

Any ideas?

floor((num-1)/9) gives the row (floor is rounding down)

(num-1) mod 9 gives the column (mod is remainder of division problem)

(row mod 3)*3 + (column mod 3) will give you 0 for A, 1 for B, 2 for C, etc

So (row mod 3)*3 + (column mod 3) + 'A' will give you the letter of the group

Or to expand it all out

group = (floor((num-1)/9) mod 3)*3 + (((num-1) mod 9) mod 3) + 'A'

x sub i, j where i is the row number and j is the row column of your number.

The groups can be labeled X sub I, J where I and J go from 1 to 3.

Each of the nine groups are defined. ie

M sub 2,3 = {34, 35, 36, 43, 44, 45, 52, 53, 54}

now you just have to get I and J from the i and j of the number whose group you want.

I = i (cel 3)

J = j (cel 3) where cel 3 means that you divide I by 3 and take the result with any non- zero integer part calling for the next highest integer.

Thus 45 is x sub 5,9 and the 5 = 2 and 9 = 3 so the 45 is in group 2,3 which is defined as the string for which you are looking.

The row/column formulas work perfectly, but I cannot make the '(row mod 3)*3 + (column mod 3)' formula work. This is more likely to be my implementation than the formula! But when I use the formula with the number 44 for example I get... 4 = E (which is one group out), when I try with the number 12 I get 5 = F?

My test implementation in powershell is as follows...

$num = 12

$row = [System.Math]::Floor(($num

$col = ($num-1)%9

(($row%3)*3 + ($col%3))

Aburr: I will have a look into your solution and see what I get! Cheers.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.

$row = [System.Math]::Floor(($num

$col = ($num-1)%9

$group_num = [System.Math]::Floor($row/

$group = [char](65 + group_num)

I don't know any powershell, but I think that last line should actually give you the letter. 65 is the ASCII value of 'A'