5
$\begingroup$

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.

Enter image description here

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!

A 5x5 table with "1, 2, 3, 4, 5" along the top row, with diagonals colored in for clarity

$\endgroup$
1
  • $\begingroup$ This is a easy puzzle for puzzle masters here, but a good exercise for our children, especially if they like mathematics. $\endgroup$ Commented Sep 13, 2016 at 12:10

4 Answers 4

7
$\begingroup$

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.)

$\endgroup$
7
$\begingroup$

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

$\endgroup$
4
  • $\begingroup$ 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. $\endgroup$
    – Gareth McCaughan
    Commented Sep 13, 2016 at 12:01
  • $\begingroup$ @GarethMcCaughan yes wording was bad, fixed. Looks like you ninja'd me anyway :) $\endgroup$ Commented Sep 13, 2016 at 12:03
  • 1
    $\begingroup$ @JonathanAllan Don't you want to swap rows 2,5 and 3,4 instead of 2,4 and 3,5? $\endgroup$
    – Anon
    Commented Sep 14, 2016 at 1:31
  • $\begingroup$ @Mc Fry, yep that is what I did, although not what I described; thanks. $\endgroup$ Commented Sep 14, 2016 at 6:04
2
$\begingroup$

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.

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

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.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.