Skip to main content

KenKen Solver

Solve a KenKen or Mathdoku puzzle from its cages and target numbers.

KenKen, also sold as Mathdoku or Calcudoku, is a Latin square split into cages. Each row and column must hold every number from 1 to the grid size exactly once, and the cells of each cage must combine, with the cage's operation, to its target number. Pick a size, click cells to group them into a cage, set the cage's target and operation, then solve.

Subtraction and division cages take exactly two cells. A single-cell cage is a given digit. Click a cage's cells again, or use Remove below, to undo it.

How it works

The solver treats the grid as a Latin square: every row and every column must contain each number from 1 to the grid size exactly once. On top of that, each cage adds an arithmetic rule. An addition or multiplication cage can cover any number of cells and its values must sum or multiply to the target. A subtraction or division cage covers two cells, where the larger value minus or divided by the smaller equals the target. A single-cell cage simply fixes that digit.

It fills the grid by backtracking, always working on the cell with the fewest remaining candidates first and checking each cage as soon as its cells are filled, so contradictions are caught early. The solver also reports when a puzzle has more than one solution.