# Special 5x5 Sudoku-like table

This is a special 5x5 Sudoku-like table.
Each row, column, and diagonal contains digits from 1 to 5 (including diagonals obtained by wrapping around the edges).
To filter duplicates (by rotation, reflection, permutations), I put numbers in ascending order (1,2,3,4,5) to the first row of the tables.

We can create another table like this, by logical deduction.

1 2 3 4 5
4 5 1 2 3
2 3 4 5 1
5 1 2 3 4
3 4 5 1 2

Find another solution, by filling the blank squares!

• This is a easy puzzle for puzzle masters here, but a good exercise for our children, especially if they like mathematics. Sep 13 '16 at 12:10

Here is another solution:

1 2 3 4 5
3 4 5 1 2
5 1 2 3 4
2 3 4 5 1
4 5 1 2 3

(There's not much to say about the method of solution. I tried putting something other than 5 in the (2,2) position; there was only one option; there were only two options for the next thing to the right, one of which quickly turned out impossible; after that it was just a matter of filling in the only possible number at each step. So this is the only solution that has 12345 along the top and doesn't have 5 in position (2,2). Perhaps there are other solutions with 5 at (2,2); I haven't checked; but I suspect not.)

Just swap each of the inner and outer pairs of the remaining rows in the original

Like so:

1 2 3 4 5
3 4 5 1 2  <-----.
5 1 2 3 4  <-.   |
2 3 4 5 1  <-'   |
4 5 1 2 3  <-----'

In fact

This and the given solution are the only two such grids with the top row ordered $[1,2,3,4,5]$
Here is some code to find them all in a split second:

def col(g, i):
return [r[i] for r in g]

def pd(g, r, c):
return [g[(r+i)%5][(c+i)%5] for i in range(5)

def nd(g, r, c):
return [g[(r+i)%5][(c-i)%5] for i in range(5)]

def iterSolutions(g, r=1, c=0):
if r == 5:
yield g
else:
for v in range(1, 6):
if v not in g[r] and v not in col(g, c) and v not in pd(g, r, c) and v not in nd(g, r, c):
ng = [x[:] for x in g]
ng[r][c] = v
nr = r + 1 if c == 4 else r
nc = 0 if c == 4 else c + 1
for sln in iterSolutions(ng, nr, nc):
yield sln

for sln in iterSolutions([[1,2,3,4,5]]+[[0]*5]*4):
print('\n'.join(' '.join(str(v) for v in r) for r in sln))
print()

1 2 3 4 5
3 4 5 1 2
5 1 2 3 4
2 3 4 5 1
4 5 1 2 3

1 2 3 4 5
4 5 1 2 3
2 3 4 5 1
5 1 2 3 4
3 4 5 1 2

• Other ways of swapping two pairs of rows do not appear to work. E.g., if you swap rows 2,3 and rows 4,5 then you get two 1s on the leading diagonal. Sep 13 '16 at 12:01
• @GarethMcCaughan yes wording was bad, fixed. Looks like you ninja'd me anyway :) Sep 13 '16 at 12:03
• @JonathanAllan Don't you want to swap rows 2,5 and 3,4 instead of 2,4 and 3,5?
– Anon
Sep 14 '16 at 1:31
• @Mc Fry, yep that is what I did, although not what I described; thanks. Sep 14 '16 at 6:04

Mirror your table to the central column, and relabel the entries:

After mirroring:

5 4 3 2 1
3 2 1 5 4
1 5 4 3 2
4 3 2 1 5
2 1 5 4 3

Spoiler:

and then apply the relabeling 5->1, 4->2, 3->3, 2->4, 1->5 so that the first row is in canonical order. This way the entry at position (2,2) is mapped to 4, yielding a distinct solution.

• Top row is meant to be fixed as [1,2,3,4,5] Sep 13 '16 at 12:15
• Yes, that's what the second part does. Sep 13 '16 at 12:15
• Might be worth adding in the result. Sep 13 '16 at 12:17
• @Matsmath If I allow permutations, rotation,reflection, from existing answer, there are so many answers. Sep 13 '16 at 12:21
• @JamalSenjaya I am afraid I don't understand your comment. Sep 13 '16 at 12:22

Here is one solution.

12345
34512
51234
23451
45123

It is obtained by

rotating the previous row by two. For example, 34512 becomes 51234. Your original solution was simply a rotation by 3. Of the possible rotations that result in a latin square, only rotations by 2 and 3 will result in the diagonals different as well.