kenkensolver

KenKen Solver

A KenKen/Calcudoku solver & rating program

https://billabob.github.io/kenkensolver/kenkensolver.html

How to use:

On the left side is the grid display. It displays the current puzzle, as well as the state of candidates on the board.

On the right side is all the solver buttons & logs. I’ll list them off from top to bottom along with their purpose.

Puzzle Entry Mode

Clicking “Enter puzzle” takes you to the puzzle entry screen. The screen itself contains instructions on how to use it, but I’ll copy them for completeness.

Leaving puzzle entry mode will automatically load in the puzzle so please make sure you’ve finished building it first.

Click gridlines to toggle them on/off.
Click the top-left-most cell of a cage to change its total and operator.

Cages must be defined with a total and an operator, in any order. “a20” and “20a” both refer to a cage where the cells must sum to 20.
Here is a table of supported operators and their aliases:

Operation Aliases
Addition a, +
Subtraction s, -
Multiplication m, x, *
Division d, /, ÷, :
Modulus r, %
Exponentiation e, ^
Bitwise OR o, |

Solver mode

Clicking “Solver” takes you back to the main solver.

“Enter puzzle import string:”
Here you can paste in a string in Simon Tatham’s format and click “Import” to load in that puzzle. These strings may be obtained from Tatham’s implementation of KenKen - generate a puzzle and click “Game > Enter Game ID…” to export it.

“Open in Sudokuwiki solver” is self-explanatory. Note this solver is limited to 6x6 puzzles and subtraction/division cages may not span more than 2 cells.

“Show candidates” may only be used immediately after a puzzle is imported. It performs the initial calculations for cage combinations and fills in Naked Singles, also removing candidates if Singles are placed and then continuing on by filling in any resulting Naked Singles and removing peer candidates after that etc… If a puzzle is easy enough it’ll be solved by this step alone.

“Step” will find and execute the easiest technique currently available in the puzzle, according to the hierarchical solver.

“x100” will do this 100 times.

“Solve” will keep stepping until the puzzle is finally solved.

Solve log:

“Detailed logs” is an option that will log all the candidates & combinations removed by the constraint propagation steps. It’s way too much information and the information isn’t particularly valuable so there’s no reason to ever turn this on.

“Log naked singles” is an option that does what it says on the tin. It’s on by default, turn it off if the logs are too long for your liking.

Batch mode

Clicking “Batch mode” brings you to the batch solver.

The first box with default text “Paste JSON here” is an input field where you can paste a JSON object containing as many puzzles as you want. An example:

[
    "6:a_a_aa_a_a_9a3ba__aa_a__aa__aa_a_,s2a9m6s3m18a5s2s3a6d3a7s2m12m20m24d2",
    "6:_4a_3aab__a_5aacaa_aa_aa__a_3a__a_,m10a7d3d3m12s2s1m12d2s1a6d2s4m90a13a5",
    "6:aa_aa_3a4babb_a_3b_3a_5a_3a_a_,a5a7s1s1m6m6d3m360a8s2a9s1d2m60m12",
    "6:a__a__a_12b_a9_aa_3a__ab,a11s3a13a6d2m12a9m6d3s2d2m12s1m60s1d2",
    "6:aa_aa__aa_5a_3abaa_aa_4a__ab_a4,a17d3s4s3a6a6m30m48s1s2d3d3m300m6d2"
]

Or you can upload a .txt file with the same format.

Mode:
This is a single character for a variety of sets of solver options.
n = Normal, respects whatever your current solver settings are
c = Cage combinations, disables every technique except for constraint propagation and the cage combination bruteforce solver.
b = Both, will output the results for n and c next to each other.

“Save output to file” is self-explanatory, as is “Run” and the Batch output text box.

Solver

This page implements a hierarchical solver & grading system, similar to the SE rating scale used to rate Sudoku puzzles. Everything is currently a work in progress and impermanent. Expect rankings & weights to change in the near future as I revamp things and implement more techniques.

The very first step of the solver is a pre-processing routine which calculates all possible cell candidates & cage combinations. If a puzzle has very large cages this could take an extremely long time. This is the major weakness of the solver.

Each step of the solver starts with the most basic techniques and climbs the ladder of difficulty until the puzzle finally yields and a candidate/cage combination is eliminated. After this a new step begins and the solver goes back to the basic techniques and climbs again. This repeats until the puzzle is solved. Puzzles are graded based on the hardest technique required to solve the puzzle, no matter how many times the technique is used. Some rating ranges are reserved pending further updates to the solver.

The technique ratings are as follows:
0: All the candidate busywork from constraint propagation etc.
0: Naked single
1: Hidden single
1.2: Cage-region intersection (pointing)
1.5: Cage-region intersection (claiming)
2: Hidden pair
2: X-Wing
2.1: Hidden Triple
2.1: Swordfish
2.2: Hidden Quadruple
2.2: Jellyfish
N-Sized Hidden subset/Fish will give rating 2+(N-2)/10, capped at 2.5.
3: Region Parity
3: Region Sum
3.1: Multi-region Parity
3.1: Multi-region Sum
3.2: Region sum (2 unknown cages in 1 region)
3.3: Region sum (2 unknown cages in >1 regions)
3.4: Region sum (3 unknown cages in 1 region)
3.5: Region sum (3 unknown cages in >1 regions)
A sum with N unknown cages will give rating 3+(N-1)/5, capped at 3.9.
4: AIC consisting of a single strong link
4.1: AIC consisting of 2 strong links
4.2: AIC consisting of 3 strong links
An AIC consisting of N strong links will give rating 4+(N-1)/10, capped at 4.9.
6: Combination of 2 cages
6.2: Combination of 3 cages
6.4: Combination of 4 cages
Combination of N cages will give rating 6+(N-2)/5 with no upper limit.

You should be familiar with most of these techniques if you’re a competent KenKen solver. The only ones that bear explaining are AIC and the cage combination solver.

AIC

The AIC implementation is fairly KenKen-specific thanks to the 2 constraints involved in the puzzle: the Latin square constraints, and the cage constraints. You have to use both to make significant progress, one or the other isn’t enough.

A basic outline of AIC is given in my article on AIC in Sudoku. The solver will always find the shortest available AIC that gives eliminations. Rings are not currently implemented.

The premises utilised by the solver are all candidate-based. Every individual candidate is a premise just like in Sudoku. Cage combinations are grouped based on their common weak inferences, for example one such grouping would be all the combinations where the cage contains a 1 in row 2. This enables cell candidates to be linked with cage combinations and vice versa.

At the moment only the basic strong inferences are implemented:
Bivalue cell candidates
Bilocal cell candidates
Grouped bilocal candidates contained within 2 cages (Group=Candidate as well as Group=Group)
Cage combinations grouped via common weak inferences

The solver also makes heavy use of the concept of Equivalence, documented in the second part of my AIC article. While in Sudoku this is a fairly niche technique, it finds great utility in Calcudoku thanks to the nature of cage combinations. Think of a 2-cell 2/ cage in a 6x6 puzzle: you know that if it contains a 3, it must also contain a 6, and vice versa. Therefore these premises are “equivalent” and may be freely swapped out. If you want to see an example this puzzle has a few of them in steps 19-21:

6:_baba_a_6a_3a_3aa_3a_4b__b_aa_aa,m12m60d3m8s1a7d3s2s1a9m24a9s1s2d2a7

Cage Combinations

Every cage has a certain set of combinations that could be valid solutions. For example in a 6x6 puzzle, a two-cell “6x” cage can only be 1x6 or 2x3, plus the permutations of those digits. A two-cell “9+” cage can only be 3+6 or 4+5, plus the permutations of those digits. Now what happens if these two cages are next to each other, like so:

.___.___.___.___.
| 6x    | 9+    |
'---'---'---'---' 

The cage combinations solver will go through every pair of two cages, including this pair. It will check which combinations of digits can satisfy both cages without contradicting each other. If the 6x cage contains 1x6 then the 9+ cage cannot contain a 6, so it must be 4+5. If the 6x cage contains 2x3 then the 9+ cage cannot contain a 3, so again it must be 4+5. This allows us to eliminate 3+6 and 6+3 as potential solutions for this cage.

The solver will check every pair of cages in this manner, then every triple, then every quadruple, then every N-tuple until it either finds an elimination or runs out of cages.

This stage is the highest-rated because it’s effectively bruteforcing larger and larger subdivisions of the puzzle until everything is bruteforced at once - it can only fail if the puzzle has more than one solution as the application “ad absurdum” would be bruteforcing the entire puzzle. These bruteforce eliminations should be covered by other techniques when they’re implemented in the future.

TODO list:

Solver:

Site:

Other stuff:

Changelog

v9.9 - 2026-03-36

Manual puzzle entry mode added, also the ability to import from shareable links with the parameter ?p={puzzle ID}.

v0.9 - 2026-02-14

Implemented AIC, moved some ratings around

v0 - 2025-07-24

First release with Naked/Hidden Single, Cage-Line Reduction, Hidden Subsets, Fish, Region Totals, Region Parity, Cage Combinations.