12/16/2013

Dekabiro Kakuro - Super Giant Kakuro

I got dekabiro - super giant - Kakuro and Slitherlink problems today. I bought them from Nikoli. The size of kakuro is 90 x 124 - really huge.

Dekabiro kakuro
I am going to test my kakuro solver "Kakkuro" with dekabiro. The biggest challenge is, I need to enter the problem! I am almost sure I am going to make mistakes and to go through the problem again and again to find the mistakes... what a daunting task!

12/08/2013

Next target - slitherlink solver

I am satisfied with my Kakuro solver. There are a few possible improvements for the Kakuro solver as I mentioned in the previous post, it wouldn't be very visible. So I want to try a solver for a different puzzle.

Sudoku (Wiki) is, of course, a candidate. It is one of the most popular puzzles in the world. But I don't want to make a Sudoku solver because:
  1. There are already a lot of good solvers.
  2. It is less challending than Kakuro. Sudoku can be solved by the same tricks as Kakuro. In a sense, Sudoku is a varation of Kakuro; a 9x9 Kakuro with no black cells except the top and leftmost cells, and with exposed solution values for some cells to guarantee a unique solution.
  3. Actually I create a solver before - in Microsoft Basic (no, it was not Visual Basic. It was a Basic with line numbers). It ran on a Z80 machine. The machine was very slow at that time but the Sudoku solver still ran fairly fast.
So what's the next? I am considering Slitherlink (Wiki/nikoli.com). It seems more challenging than Kakuro.

I am also considering C# as a language instead of C++. I have been using C++ for many years but I want to try something new. It should be a fun!

12/06/2013

Kakuro Solver - Ideas for improvement

My kakuro solver is fast and actually I am really satisfied with the result. But there are kakuro problems with a unique solution which the solver needs to backtrack to solve. In general, the backtracking is costly and there is room for improvement.

There are two ways to improve backtracking; one is to improve the backtracking itself and the other is to avoid the backtracking.

Improving backtracking
Roughly speaking, the solver does two things;

  1. Bitwise calculation
  2. Picking up a cell without solution and try all possible solutions

What to pick up at the step is very important. For example, let's assume the solver already knows the solutions for the gray cells below and is about to start backtracking.
The current implementation searches for a cell without solution from left to right and then from top to bottom. In this case, the solver picks up cell 1 and try the first possible solution. The solution of cell 2 is determined easily. If the solver fails to find a solution of the problem soon, it picks up another cell for the next level backtracking and that will be cell 3.

The issue here is, the backtracking at cell 3 may do the same thing again and gain for each possible solutions because cell 1 and 3 are far away from each other and their results of backtracking may not affect each other.

If the solver picks up a cell for the second backtracking based on the result of the first backtracking, it could backtrack more efficiently.

Avoiding backtracking
I may be able to reduce the chance of backtracking by adding other deduction rules. There are two rules I didn't use.


  1. I already use the rule "if a cell has only one possible solution value, the value is the solution for the cell and the other cells in the same entry cannot use the solution value". This rule can be extended for multiple cells, that is, "if N cells in an entry have the same set of N possible solutions, the other cells in the entry cannot have the possible solutions."
    For example, let's assume we have a 15-in-five entry. If the first and second cells in the entry have only two possible solutions {1, 2}, then the other three cells cannot have {1, 2}. If the third cell have the solution "1", then the first two cells have the only one solution "2". One of them has no solution!
    Another example is, again, we have a 15-in-five entry. This time, the first cell's possible solutions are {1, 2}, the second's are {2, 3}, and the third's are {1, 3}. Each of these cells has two solutions but if you look at these three cells as a whole, they have the common three possible solutions {1, 2, 3}. So the other two cells cannot have {1, 2, 3}.
  2. I already use the rule "if a solution value in an entry must be the solution in a cell and only one cell in the entry can have the solution value, the cell's solution is the solution value and cannot have other values". This rule also can be extended for multiple cells: "if N solution values in an entry must be the solutions and only N cells in the entry can have the solution values, the cells' solutions are one of the solution values and cannot take any other values."
    For example, let's assume we have a 17-in-five entry. The possible solution sets are {1, 2, 3, 4, 7} and {1, 2, 3, 5, 6}. {1, 2, 3} are common, so they must be a solution of a certain cell in the entry. If each cell in the entry currently have possible solution values like this; the first {1, 2, 3, 4, 5, 6, 7}, the second {1, 2, 3, 4, 5, 6, 7}, the third, fourth and fifth {3, 4, 5, 6, 7}. Now the two possible solution values "1" and "2" appear in the first two cells only. So the first two cells cannot take other values.

These two rules probably work but they look costly because you need to enumerate combinations of cells or solution values to use these rules. As the current solver can solve most of Kakuros without backtracking, if I apply these rules carelessly, the total solution can easily get worse.