SOLVING THE KAKURO PUZZLE

advertisement
SOLVING THE KAKURO PUZZLE
Andreea Erciulescu
Department of Mathematics, Colorado State University, Fort Collins (Mentor: A. Hulpke)
Abstract
The Smith Normal Form
Kakuro puzzles are NP-complete (”Non-deterministic Polynomial
time”). Although brute-force guessing is a possible way to solve them,
a better weapon is the understanding of the various combinatorial forms
that entries can take for various pairings of clues and entry lengths. This
poster presents one approach towards completing an algorithm to solve
Kakuro without guessing.
If A is a matrix with entries in Z, then there are invertible matrices P
and Q over Z such that P AQ is in Smith Normal Form: there are nonzero
αi ∈ R, for each i < m, such that ai divides ai+1 for each i < m, defined as
follows
Puzzle’s Definition
Kakuro is a kind of logic puzzle that is often referred to as a mathblack and white cells. The digits 1 to 9 must be filled into all the white
cells so that they satisfy the clues given in some of the black cells. The
clues specify the sum of the numbers in the row of successive white cells
0 ··· ··· ··· 0
α1 0
0 α2 0 · · · · · · · · ·
... ... . . . · · · · · · · · ·
0 · · · αm · · · · · ·
0 · · · · · · ... · · ·
...
0
0
...
0 ··· ··· ··· ··· ···
These puzzles are regular features in most, if not all, math-and-logic puzzle publications in the United States. The popularity of Kakuro in Japan is

cihi, where hi are the ho-
i
entries in the solution

0


0

0
 .[Morandi]

0
... 


0
Now we have that P ∗ N ∗ Q = M , for N defined above.
From (1) and (2) we get the following system:
(
X =Q·Y
M ·Y =P
to the right or the column of successive white cells below. No row or column of successive white cells can have a digit repeated.
• consider all combinations of partial +
X
mogeneous solutions and ci are small integers that would give small














Introduction
ematical transliteration of the crossword. Kakuro is given on a grid of
Combinatorial Search
−1
• look only for the solutions that satisfy the puzzle ( numbers between
1 and 9 and no duplicates on the same column and same row)
• a possible solution is a linear combination of the reduced basis vectors
• use backtracking for examining feasible solutions, by systematically
eliminating infeasible solutions
Combinatorial search is among the hardest of common computational
problems: because of the exponentially large number of possibilities, the
·B
solution time grows exponentially with the size of the puzzle. We first
Therefore, we have the solution to the inhomogeneous equation M ·
Y = P −1 · B and the solution to the homogeneous equation M · Y = 0.
However, the entries are possibly large. For this, we implement Lattice
Reduction to find the small integer solutions.
immense, second only to Sudoku. (You can try out some of these puzzles
detect the vectors hi that have few nonzero entries corresponding to the
entries in the particular solution that need to be changed. For these, we
test the coefficients ci and prune the tree whenever the choice determines
the entry in the solution.
on the following website: http://www.kakuropuzzle.com)
Find the small integer solutions
A 4 × 4 example
• find small integer solutions that respect the puzzle’s conditions
• Lattice Reduction
The Lattice Reduction algorithm can be used to reduce the 2-norms
of a set of vectors. We use this algorithm on the set formed with both the
homogeneous and the inhomogeneous solutions and as solution get the
rows of






Methods
• We consider this puzzle a linear problem with variable entries and
we solve it over Z
−2
6 −2
1 −1
0
0
1 −1
9 0
6 0 0


0 −1 1 0 0 0 

1 −1 0 −1 1 0 

1 −1 0 −1 0 1
Observe that lll[4] − lll[3] − lll[2] = [1, 3, 1, 4, 2, 3, 2, 1] is the solution to
the puzzle.
Future Directions and Conclusions
and the resulting set of vectors spans the same initial space.
Method:
• Smith Normal Form and Lattice Reduction
• Solving a Kakuro puzzle is a NP problem. The complexity class NP-
• Combinatorial search
complete (standing for Nondeterministic Polynomial time) is often
found in the computational complexity theory. For these problems,
Compute the integer solutions
one can quickly verify a solution, whenever it is given. However,
there is no efficient way to think about a solution in the first place.
Let the matrix of equations be N, defined as follows: N is a nrow × ncol
Solving these problems requires computer algorithms and a large
matrix with entries in {0, 1} ⊂ Z, where nrow represents the number of
amount of time.
equations and ncol represents the number of unknown variables.
• We have tested puzzles up to the size 25x35 and the algorithm gives

1 1 0 0 0 0 0 0

0

0

N =
0

1

0
0 1 1 1 0 0
0 0 0 0 1 1
0 1 0 0 1 0
0 0 1 0 0 1
1 0 0 1 0 0

the right solution.

0

1


0

0

1
• We are looking at a better way to enter the information from the puzzle.
• We would like to eliminate the infeasible solutions earlier.
2
Now, let X be the vector of unknown variables (the solution to the
Let v, w be two vectors that form a basis for Z and let k ∈ Z. If k ∗ w
puzzle) and B be the matrix whose entries are the clues from the black
is close to the projection of v onto w, then v and v − k ∗ w are a new basis
cells, in the puzzle.
for Z2 and v − k ∗ w is shorter. The LLL algorithm repeats this for all pairs
B = (4, 7, 6, 4, 7, 6)
T
Therefore, X’s entries are elements of the set of numbers {1, 2, ..., 9},
no duplicates, and solution to the puzzle is the solution to the system
N × X = B, which can be solved over integers, using the Smith Normal
form. (1)
• solve the homogeneous and the inhomogeneous equations over the
integers (there are infinitely many solutions)
• compute the Smith Normal Form of the matrix of equations
• We would like to know what would be the exact range of coefficients
that gives the solution.
Bibliography
of vectors, until it gives a nearly orthogonal, reduced basis.
Now we have the homogeneous solutions and the partial one, which satisfies the linear system, given by the rows of the matrix


1 −1 0 −1 1 0 0 0


 0 0 1 −1 0 −1 1 0 

lll = 
 1 −1 0 0 0 0 −1 1 


2 2 2 3 2 2 2 2
Since most of the times it is not a solution for the puzzle, we need to
proceed to the next step.
Morandi Morandi, Patrick, The Smith Normal Form of a Matrix , 17
February, 2005
LLL Lenstra, Lenstra, Lovasz L., Factoring Polynomials with Rational
Coefficients,1982
Download