Skip to content
← blog  /  tools

Number fill-in generator in Python: digits behave like words

2026-12-04  ·  4 min read  ·  tools

With ten digits instead of 26 letters, you would expect more numbers that can trade places in a grid. In 500 random grids it hardly mattered: one starting number still left one way to fill 96 to 99 % of them.

A number fill-in is a fill-in puzzle with digits: an empty grid and a list of numbers, grouped by how many digits they have, and the solver fits every number in. No words to know and no sums to work.

The worry with digits is that there are only ten of them, so you might expect more numbers that agree where the grid crosses them, and more grids that fill in two ways. On 31 October 2026 we measured it, with the same grid builder and the same counter as for words.

The short version#

  • Easy grids (14 random numbers of 3 to 6 digits): one way to fill with no number printed in place in 76 % of 300. With one starting number, 99 % could be made to fill in one way.
  • Medium grids (20 numbers of 3 to 7 digits): 73 % and 96 % of 200.
  • For words, in our fill-in post, the same counts were 78 % and 97 % for easy grids and 71 % and 94 % for medium ones, with words of 3 to 7 letters for easy and 3 to 10 for medium. So the digits made no real difference.
  • The second way was again two numbers trading places where they cross matching digits, like 722 and 882.
  • The generator needed 1.02 sets of numbers a puzzle and 10 to 12 ms.

The code#

The grid comes from best_grid() in our crossword generator post, and the count from fillings() in the fill-in post. What is new is the numbers:

Random fair numbers in a fill-in grid with one way to fill itpython
import random
from crossword import best_grid, show   # from our crossword generator post
from fill_in import fillings            # from our fill-in generator post


def fair_number(length, rng=random):
    """A number of `length` digits that does not start with 0 and is not one digit over and over (like 4444)."""
    while True:
        n = str(rng.randint(10 ** (length - 1), 10 ** length - 1))
        if len(set(n)) > 1:
            return n


def numbers(count, shortest, longest, rng=random):
    out = set()
    while len(out) < count:
        out.add(fair_number(rng.randint(shortest, longest), rng))
    return sorted(out)


def make(count=14, shortest=3, longest=6, rng=random, tries=100):
    """A grid and a starting number with which it fills in exactly one way; new numbers when no start works."""
    for k in range(1, tries + 1):
        grid, placed = best_grid(numbers(count, shortest, longest, rng), rng=rng)
        for given in rng.sample(range(len(placed)), len(placed)):
            if len(fillings(placed, given)) == 1:
                return grid, placed, given, k
    raise RuntimeError("no grid that fills in one way")
Run itpython
grid, placed, given, draws = make(rng=random.Random(3))
print(show(grid))
print("numbers:", len(placed), "| starting number:", placed[given][0], "| ways:", len(fillings(placed, given)),
      "| without it:", len(fillings(placed)))

With that seed it placed all 14 numbers and picked 7061 to start:

The finished gridtext
. . . . 9 . . . . . .
. . . . 5 . . 7 . . .
. . 8 7 7 2 5 8 . . .
. . . 5 . . . 7 . . .
. . . 6 . . . . . . .
. 3 7 1 9 5 2 . 7 2 0
9 . . 1 . 1 . . 0 . .
9 . . 5 . 6 . . 6 . .
1 . . . . 4 1 4 1 . .
6 6 7 2 5 2 . 7 . . .
. . . 6 . 5 . 9 . . .
. . . 3 . . . 9 5 7 1

This grid would fill in one way even without 7061; about a quarter of easy grids would not.

Why digits do not hurt#

A swap needs two numbers of the same length that agree at every square where the grid crosses them. These grids are sparse: an easy one had 13.2 crossings for 13.9 numbers, so a number crosses about two others and a swap has to agree on only one or two digits, with letters as with digits. The counts barely moved. What does matter is the starting number, exactly as with words: it breaks any swap it touches.

fair_number() keeps two rules a book needs: no number starts with 0, and none is one digit over and over, like 4444.

A whole book, not one grid#

Our number fill in book maker checks every puzzle: a second program, written apart from the one that makes the puzzles, tries every way to fit the listed numbers into the empty grid, starting from the number already in place, and finds exactly one. Every run of two or more boxes is a number from the list, each number is in the grid once, the grid is one connected piece, and the list is grouped by length.

Easy books use numbers of 3 to 6 digits, up to 14 a puzzle; medium 3 to 7 digits, up to 20; hard 4 to 8 digits, up to 26. The number list is set in the grid's own typeface with a slashed zero, and the book is checked against KDP's paperback specs before you can download it.

written