Advanced maths

Partial Latin square completion calculator with exact solution counts

Complete a small partially filled Latin square, count all labeled completions when the exact search finishes, and report uniqueness with a witness.

Your numbers

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Behind the numbers

How this calculation works

Complete a small partially filled Latin square, count all labeled completions when the exact search finishes, and report uniqueness with a witness.

THE FORMULAEach row and each column contains every symbol0,…,n−1 exactly once; completed squares preserve every supplied clue.

A worked example

For[[0,1,2],[1,2,−1],[2,−1,1]], the two blanks are forced to0. The resulting cyclic Latin square is the unique completion of these clues.

Good to know

Order2–6 with symbols0…n−1 and blank marker; validate clues and count all completions only when the complete backtracking search finishes under a fixed state cap. Return one witness, exact count and uniqueness status. Do not quotient by relabelings or claim zero completions after a cap.

Rows and columns define the constraint

A Latin square of order n is an n by n array using n symbols, each occurring exactly once in every row and every column. A partial square fixes some entries and leaves holes. Completion asks whether the holes can be filled without changing any clue. Counting completions is a stronger task than finding one convenient completed grid.

This page has no Sudoku subgrid constraints. It also does not identify squares under row permutations, column permutations or symbol relabeling. Unless those equivalences are explicitly imposed, differently labeled completed arrays count separately. That convention matters even for an empty square, where many completions may describe isomorphic algebraic patterns but remain distinct arrays on the entered labels.

Two forced zeros complete the cyclic Latin square012120201Two blank cells are forcedEvery row: {0,1,2}Every column: {0,1,2}Completion count = 1
Scroll across to see the full diagram.
For[[0,1,2],[1,2,−1],[2,−1,1]], the two blanks are forced to0. The resulting cyclic Latin square is the unique completion of these clues.

Compare this with the Exact cover calculator with solution counts and chosen subsets. Accept a symbol grid with holes, enforce one copy of every symbol in each row/column, and count/construct completions with a row-column-symbol certificate. The exact-cover page expects arbitrary user-enumerated subset rows; it does not construct or validate Latin constraints or a completed symbol square. No Sudoku subgrid constraints are added.

Use an explicit blank marker

Enter a square JSON array with symbol values0 through n−1 and−1 for each blank. Zero is a valid symbol, so it cannot also mean empty. Every row must have n entries and the order must lie within the supported range. A repeated fixed symbol in one row or column contradicts the Latin condition immediately.

A clue-valid partial square is not necessarily completable. For example, available symbols can become mutually incompatible across several holes even when no row or column currently contains a duplicate. The calculator therefore separates clue validation from the actual completion search. An error in the clue format should not be confused with an exact proof that a well-formed partial square has no completion.

Propagate allowed symbols at a hole

At an empty cell, remove symbols already used in its row or column. The remaining symbols are its candidates. A hole with no candidate rules out that branch. Choosing a hole with few candidates can reduce search substantially, but the choice is an efficiency heuristic and does not change which completed arrays satisfy the original constraints.

After placing a candidate, update the corresponding row and column restrictions and continue. When all cells are filled, record one valid completion. Then undo the placement and examine every remaining branch if an exact count is requested. Stopping after the first solution proves existence only. It cannot establish uniqueness or give the total number of solutions.

Distinguish counts from search limits

A completed enumeration with count zero proves infeasibility. A completed enumeration with count one proves uniqueness on the entered row, column and symbol labels. A completed enumeration with count above one proves multiple completions. If the search stops at a state or time cap, its current count is incomplete and must not be reported as the exact total.

Likewise, finding two solutions is enough to disprove uniqueness but not to finish a full counting task. The page should state whether it exhaustively counted all completions or merely detected nonuniqueness. A saved witness is useful even when other solutions exist, provided the result does not hide the distinction between that witness and the requested exact count.

Fill the default two holes

The first default row is[0,1,2]. The second row is[1,2,blank], so its missing symbol is0. The third row is[2,blank,1], also missing0. Placing those zeros respects the columns as well: the completed columns are[0,1,2],[1,2,0] and[2,0,1]. Every row and column contains the required symbols exactly once.

Both blanks are forced by their row requirements, so no other completion is possible. The reported count is one. For comparison, an entirely empty labeled square of order two has two completions, and an empty order-three square has twelve. Those counts use all row, column and symbol labels as distinct; reducing the first row and column by symmetry would count a different object.

Check a constructive certificate

The returned witness should have the same shape as the input and no blank values. Each row and column must be a permutation of0 through n−1, and every fixed input value must remain unchanged. These conditions verify a solution independently of the backtracking procedure that produced it. They do not alone prove that the solution is unique.

An independent exact-cover formulation provides another counting check: each candidate placement covers a cell, a row-symbol requirement and a column-symbol requirement. The current calculator constructs and validates those Latin-specific conditions directly. The general exact-cover page instead expects an arbitrary pre-enumerated set system, so copying only a final count between the two without checking conventions would be unsafe.

Understand why the scope is small

Latin-square counts grow quickly with order, and a nearly empty square can be harder than a heavily constrained one of the same size. The declared maximum order is therefore not a promise that every instance of that order will finish within the search cap. Resource exhaustion should leave exact counting unresolved rather than replace it with an unexplained estimate.

Use the page to understand clue consistency, forced placements and finite completion ambiguity. It does not prove that a grid is random, suitable for a particular experimental design or secure as a puzzle. Additional balance, orthogonality or puzzle requirements belong to other mathematical tasks. Here, the result concerns exactly the entered Latin row-and-column conditions and the completeness status of the search.

A few questions, answered

Why use−1 rather than0 for blanks?

Zero is one of the permitted Latin symbols, so a separate marker is needed for an empty cell.

Does this include Sudoku boxes?

No. Only the Latin row and column conditions are imposed; no extra subgrid constraints are assumed.

Can valid clues still have no completion?

Yes. Absence of an immediate duplicate is necessary but does not guarantee that all holes can be filled consistently.

Does the first found square prove uniqueness?

No. Uniqueness requires every other search branch to be excluded, or a completed count of one.

Find your calculator

Start typing to explore the library.