# Determining if two Sudoku boards are in the same equivalence class

Consider the following $9 \times 9$ Sudoku board

963 174 258
178 325 649
254 689 731

821 437 596
496 852 317
735 961 824

589 713 462
317 246 985
642 598 173


and the following partially filled Sudoku board

.6. 1.4 .5.
2.. ... ..1
..8 3.5 6..

8.. 4.7 ..6
..6 ... 3..
7.. 9.1 ..4

5.. ... ..2
.4. 5.8 .7.
..7 2.6 9..


The task is to find out if they are in the same equivalence class.

• Relabeling symbols (9!)
• Band permutations (3!)
• Row permutations within a band (3!3)
• Stack permutations (3!)
• Column permutations within a stack (3!3)
• Reflection, transposition and rotation (2).

How can I find out (without testing for all possible combinations of the unsolved board) if they are in the same equivalence class?

The approach should probably be to define a canonical form for the solved puzzle and then find a method to derive the canonical form from any Sudoku board. But what is my choice of canonical form and how to derive the canonical form from any Sudoku board (given that we have a solved board)?

• +1 for interesting question, however i got no idea of how to answer aha! – Francesco Alem. Aug 25 '16 at 11:52
• +1 Excellent question - cannot help you though. – Kevin Aug 25 '16 at 12:07
• Maybe you can find some ideas in the following paper? arxiv.org/abs/1201.0749 – David Robertson Aug 29 '16 at 20:17
• My apologies: I just asked a very similar question. – richard1941 Dec 22 '16 at 18:55

Ok - your initial question got me thinking (despite the comment I left above). Let $X$ denote the set of all Sudoku grids. Then it is clear that this set is finite. Let $G$ denote the symmetry group of a Sudoku grid. Then it is clear that each element of $G$ is a map from one valid grid to another, it means $G$ has only a finite number of symmetries.

So then, let us mean by equivalent grids those that can be mapped to (in $X$) by one (or more) of the symmetries in $G$. For any $A \in X$ all grids equivalent to $A$ are essentially the same as $A$. So for all grids equivalent to (say, w.l.o.g) $A_i$ we can partition $X$ into these equivalence classes so that $X = \bigcup_{i}A_i$ (incidentally, I think that $|A|$ would be the orbit of $X$).

The number of orbits can be counted using Burnside's Lemma

To eliminate relabeling, you can relabel the grid such that the first row would be 123/456/789. In the example, the substitution string "473682591" will make the first row "123456789". That is, replace 1 with 4, 2 with 7, and so on. It eliminates stack and column permutations.

To eliminate band and row permutations, order the rows according to the first column in ascending order, while keeping each row in its respective band, and possibly switching the middle and bottom bands. Thus, the left column would be added to the canonical form.

In the example, the left column would have been relabeled to 147/965/832. The bands and rows have to be reordered to make the column 147/238/569.

More cells have to be added to make sure that the combination of all these would lead to a unique board. I do not know how many more cells it would take or which locations would be most suitable. (Perhaps, all the diagonals in each 3x3 block?)

Lastly, they have to be grouped in equivalent classes. Each group would be based on stack and column permutation and column/row transposition (6 x 6x6x6 x 2) of one. Choose the lowest ordered one to represent the group. The lowest ordered (left column) is 145/236/789.