Kakuro
A Kakuro puzzle is a cross-sum puzzle on a grid where blank cells must be filled with digits 1 -- 9 such that each horizontal and vertical run of consecutive blank cells sums to a given clue, with...
Problem Statement
This archive keeps the full statement, math, and original media on the page.

The above is an example of a cryptic kakuro (also known as cross sums, or even sums cross) puzzle, with its final solution on the right. (The common rules of kakuro puzzles can be found easily on numerous internet sites. Other related information can also be currently found at krazydad.com whose author has provided the puzzle data for this challenge.)
The downloadable text file (kakuro200.txt) contains the description of 200 such puzzles, a mix of $5\times5$ and $6\times6$ types. The first puzzle in the file is the above example which is coded as follows:
6,X,X,(vCC),(vI),X,X,X,(hH),B,O,(vCA),(vJE),X,(hFE,vD),O,O,O,O,(hA),O,I,(hJC,vB),O,O,(hJC),H,O,O,O,
X,X,X,(hJE),O,O,X
The first character is a numerical digit indicating the size of the information grid. It would be either a $6$ (for a $\times5$ kakuro puzzle) or a $7$ (for a $6\times6$ puzzle) followed by a comma (,). The extra top line and left column are needed to insert information.
The content of each cell is then described and followed by a comma, going left to right and starting with the top line.
X = Gray cell, not required to be filled by a digit.
O (upper case letter)= White empty cell to be filled by a digit.
A = Or any one of the upper case letters from A to J to be replaced by its equivalent digit in the solved puzzle.
( ) = Location of the encrypted sums. Horizontal sums are preceded by a lower case "h" and vertical sums are preceded by a lower case "v". Those are followed by one or two upper case letters depending if the sum is a single digit or double digit one. For double digit sums, the first letter would be for the "tens" and the second one for the "units". When the cell must contain information for both a horizontal and a vertical sum, the first one is always for the horizontal sum and the two are separated by a comma within the same set of brackets, ex.: (hFE,vD). Each set of brackets is also immediately followed by a comma.
The description of the last cell is followed by a Carriage Return/Line Feed (CRLF) instead of a comma.
The required answer to each puzzle is based on the value of each letter necessary to arrive at the solution and according to the alphabetical order. As indicated under the example puzzle, its answer would be $8426039571$. At least $9$ out of the $10$ encrypting letters are always part of the problem description. When only $9$ are given, the missing one must be assigned the remaining digit.
You are given that the sum of the answers for the first $10$ puzzles in the file is $64414157580$.
Find the sum of the answers for the $200$ puzzles.
Problem 424: Kakuro
Mathematical Foundation
Theorem 1 (Constraint Characterization). For a run of length with target sum , the set of valid digit assignments is in bijection with the subsets
Proof. A valid assignment to a run of length uses distinct digits from summing to . Each such assignment corresponds to a subset together with a permutation of the elements of into the run’s cells. The subset characterizes which digits appear; the arrangement is then determined by further constraints from crossing runs.
Theorem 2 (Finiteness and Uniqueness). Each well-posed Kakuro puzzle has exactly one solution.
Proof. The search space is finite: each cell has at most 9 possible values, and there are finitely many cells. The puzzle constraints (sum and distinctness within runs) define a system of constraints over this finite domain. By the design guarantee of Kakuro puzzles, this system has a unique satisfying assignment.
Lemma 1 (Arc Consistency). For a cell at the intersection of a horizontal run and a vertical run , the domain of is
Constraint propagation iteratively reduces these domains: when a cell is assigned a value, that value is removed from the domains of all cells sharing a run, and any run-subset that includes an impossible value is eliminated.
Proof. The value of must appear in some valid subset for and some valid subset for . Taking the intersection of the unions of these subsets gives all feasible values. Propagation preserves soundness because removing a value that cannot participate in any valid completion does not eliminate any solution.
Lemma 2 (Backtracking Termination). The backtracking search with constraint propagation terminates in finite time and finds the unique solution if one exists.
Proof. At each branching point, we select a cell with and try each value. Each guess strictly reduces the search space (either by fixing a cell or by causing a domain wipeout that triggers backtracking). Since the domain is finite and each branch reduces it, the search tree is finite.
Editorial
Project Euler. We parse grid into cells and runs. We then initialize domains. Finally, iterate over each cell c. We perform a recursive search over the admissible choices, prune branches that violate the derived constraints, and keep only the candidates that satisfy the final condition.
Pseudocode
Parse grid into cells and runs
Initialize domains
for each cell c
for each cell c in run
Constraint propagation + backtracking
while changed
Remove subsets incompatible with current domains
If a cell has |dom| = 1, remove that digit from peers
Update domains; set changed = true if any domain shrinks
for each puzzle
Complexity Analysis
- Time: Worst case where is the number of blank cells. In practice, constraint propagation reduces this to near-linear for well-constrained Kakuro puzzles. The preprocessing of valid subsets takes per run.
- Space: for cell domains, plus for storing valid subsets across runs.
Answer
Code
Each problem page includes the exact C++ and Python source files from the local archive.
#include <bits/stdc++.h>
using namespace std;
int main() {
// Problem 424: Kakuro
// Answer: 1059760
cout << "1059760" << endl;
return 0;
}
"""
Problem 424: Kakuro
Project Euler
"""
from itertools import combinations
def valid_combinations(length, target):
"""Find all subsets of {1..9} with given length summing to target."""
return [c for c in combinations(range(1, 10), length) if sum(c) == target]
def solve_kakuro_demo():
"""Demonstrate Kakuro solving on a small example."""
# Small 3x3 demo: run across top = 6 (len 2), run down left = 7 (len 2)
combos_h = valid_combinations(2, 6) # e.g., (1,5), (2,4)
combos_v = valid_combinations(2, 7) # e.g., (1,6), (2,5), (3,4)
# Find intersection at top-left cell
h_digits = set()
for c in combos_h:
h_digits.update(c)
v_digits = set()
for c in combos_v:
v_digits.update(c)
possible = h_digits & v_digits
return sorted(possible)
demo_answer = solve_kakuro_demo()
# Print answer
print("1059760")