Chapter 22
BlockNumber
BlockNumber is the puzzle of counting up each region. The grid is partitioned into irregular regions (the “blocks”), and every block carries an implicit local counter: a block of size must be filled with the numbers , each exactly once. Some cells inside blocks are pre-filled as clues. A single further rule knits the blocks together: no two cells that are adjacent in the king-move sense (orthogonally or diagonally) may hold the same number, even across a block boundary.
The king-move constraint is the puzzle’s signature. Where Sudoku forbids repetition along rows, columns, and regions, BlockNumber forbids repetition in every neighbourhood around every cell. This makes solving feel like threading a low-collision schedule: small blocks (size or ) are forced by their neighbours’ values, and the force propagates outward through the king-move contact graph.
BlockNumber is one of the younger Japanese pencil puzzles collected in Alex Bellos’s Puzzle Ninja anthology. The block partition is hand-designed so that the combination of “count to block size” and the king-move constraint yields a unique solution. Variants of the puzzle run under different English names (Fillomino-with-bounds, LITS-counter, etc.), but the core rule set is stable.
Rules and a small instance
A BlockNumber puzzle is an grid of cells, partitioned into disjoint connected blocks covering every cell. Some cells carry pre-filled positive-integer clues. A solution assigns to every cell a positive integer such that:
For every block of size , the values assigned to its cells are exactly , each occurring once.
For every pair of cells and with (i.e. king-move adjacent), the values assigned are different.
Every pre-filled clue is preserved.
Figure 22.1 is a BlockNumber with four blocks of sizes and two clues.
The programming model
Assign each cell an integer variable . If the cell belongs to a block of size , its domain is .
Block domains and uniqueness
For every block of size , Together these assert that ’s values are a permutation of .
King-move no-equal
For every cell and each of its eight king-move neighbours with lying inside the grid: Because the relation is symmetric, the constraint is posted only for ordered pairs with lexicographically.
Clue preservation
For every pre-filled cell with clue ,
A solver in thirty lines
from ortools.sat.python import cp_model
def solve_blocknumber(blocks, R, C):
"""blocks: list of dicts {(r,c): clue or ""};
each dict is one block."""
m = cp_model.CpModel()
v = {}
for block in blocks:
n = len(block)
for (r, c) in block:
v[(r, c)] = m.NewIntVar(1, n, "")
# Clue preservation
for block in blocks:
for (r, c), clue in block.items():
if isinstance(clue, int):
m.Add(v[(r, c)] == clue)
# Block all-different
for block in blocks:
m.AddAllDifferent([v[c] for c in block])
# King-move no-equal
for (r, c) in v:
for dr in (-1, 0, 1):
for dc in (-1, 0, 1):
if (dr, dc) == (0, 0): continue
nb = (r + dr, c + dc)
if nb in v and nb > (r, c):
m.Add(v[(r, c)] != v[nb])
s = cp_model.CpSolver()
s.Solve(m)
return {c: s.Value(v[c]) for c in v}
The toy of Figure 22.1 solves uniquely in about milliseconds.
A hard instance
Figure 22.3 is a BlockNumber with twelve blocks of mixed sizes (ranging from to ), a single clue, and cells to fill. The block partition is visible from the thick boundary lines. CP-SAT returns the unique solution in about milliseconds.
Sources. BlockNumber is a contemporary Japanese pencil-puzzle kind collected in Alex Bellos’s Puzzle Ninja: Pit Your Wits Against the Japanese Puzzle Masters (Guardian Faber, ), where the style is sometimes attributed to the Puzzle Communication Nikoli tradition of irregular-region fillers. The king-move constraint distinguishes BlockNumber from its closer relative Fillomino (Chapter ), which forbids only orthogonal equal neighbours and has no fixed block sizes. Computational complexity of BlockNumber is open; like most region filler puzzles, it is likely NP-complete under suitable complexity-theoretic reductions, but no published proof is known.