even the combination of a sensible choice of the ini-
tial puzzle configuration and simple heuristics, imple-
mented in a standard local search optimisation algo-
rithm (modified steepest ascent hill-climbing) is suf-
ficient to ensure the reliable and reasonably efficient
solution of Sudoku puzzles of different complexity
ratings (Jones et al., 2007). Approaches to solving
Sudoku puzzles that can employ domain information
to greatly prune the search space that need be consid-
ered in locating the solution, while simple, may prove
effective. That is the approach taken in this paper,
in analysing the potential usefulness of Quasi-Magic
Sudoku for code generation.
3 PROBLEM SIZE AND CELL
INTERRELATIONSHIPS
For Quasi-Magic Sudoku, the additional constraint
that within each mini-grid, every row, column and di-
agonal must sum to 15 ± ∆ is applied. For the case
∆ = 0, it may trivially be shown that there are no
valid grids (as the value 5 must lie in the centre of
a mini-grid satisfying this property, but 5 cannot lie in
the centre of every mini-grid (Forbes, 2007a)). For
the case ∆ = 1, a similar result holds for the posi-
tioning of the values 1 and 9 (Forbes, 2007a). For
∆ = 9, no additional constraints are being imposed,
leading to a standard Sudoku grid (as every row, col-
umn and diagonal in a Sudoku mini-grid will nec-
essarily sum to a value in the range 6, . . . , 24); the
number of valid grid arrangements is known to be
6, 670, 903, 752, 021, 072, 936, 960 (Felgenhauer and
Jarvis, 2006).
The cases of ∆ in the range 2, . . . , 8 are of greater
interest here, but only for the case ∆ = 2 is it cur-
rently known how many valid grids are possible. This
number, 248, 832, is reported as a new result here,
determined through enumeration using the solver de-
scribed in Section 4, and proven mathematically in
(Jones et al., 2008). No work has yet been published
on other cases, hence we pursue the case ∆ = 2 in this
paper. Even in this heavily constrained case, these are
many possible valid grids. Hence, even with givens
added to an empty grid, a typical search space, for
example one arising from a local search optimisation
approach to solving grids, is deceptively large.
The imposition of the additional Quasi-Magic Su-
doku constraint leads to interrelationships between
cell values that are specific to the value of ∆. These in-
terrelationships may be used to identify arrangements
of cell values that are not possible in a valid grid, lead-
ing to sets of rules that may be employed in pruning a
search space of possible grid solutions for any puzzle.
In order to explain the pruning rules for the case
∆ = 2, we introduce here some additional terminol-
ogy for Sudoku grids: mini-grids are organised into
bands (horizontally) and stacks (vertically). Hence,
each Sudoku grid has 3 bands of 3 mini-grids, and
3 stacks of 3 mini-grids. With this terminology, the
quasi-magic pruning rules can now be written as be-
low. The first nine rules are derived and reworded
from results previously reported in (Forbes, 2007a),
and proved in (Jones et al., 2008) which also adds the
tenth rule as an extension to those results:
1. Only 3, 4, 5, 6 or 7 can be in the centre of any
mini-grid. (A 1, 2, 8 or 9 would violate the quasi-
magic constraint for one or more rows, columns
and diagonals within the mini-grid.)
2. The value 5 can only be placed in the centre cell,
or in a corner cell, of any mini-grid.
3. Every band and stack must contain exactly one
mini-grid with a 5 in its centre cell (and exactly
3 mini-grids have 5 in the centre cell within the
entire grid).
4. At most one mini-grid will have 3 in its centre
cell; the same applies for the value 7.
5. If there is a mini-grid with centre 3 and a mini-
grid with centre 7, then those mini-grids must be
either in the same stack or the same band.
6. The values 6 and 7 can not form mini-grid centres
in the same stack or band.
7. The values 3 and 4 can not form mini-grid centres
in the same stack or band.
8. In any mini-grid, the values 1 and 2 can not lie in
the same row, column or diagonal.
9. In any mini-grid, the values 8 and 9 can not lie in
the same row, column or diagonal.
10. If all mini-grid centres are 4, 5 and 6 (i.e. there are
no 3 or 7 centres) then the values 4 and 6 can only
lie in centre and corner cells in any mini-grids.
The givens rule out some possible placements, re-
ducing the size of the search space. (Note that each
given should be chosen such that it is neither a logi-
cal consequence of any other given, nor of the quasi-
magic rules; hence their consequence in ruling out
possible placements is relatively small, especially as
there are fewer of them than would be the case in Su-
doku.) The number of total possible combinations of
remaining values, and therefore the number of dis-
tinct states in the search space (an indicator of search
space size), is reduced to the number of permutations
of non-given values within their respective mini-grids
ICAART 2009 - International Conference on Agents and Artificial Intelligence
248