← workshop ← workbench

The Ulam Spiral

where the primes line up
self-test …
this diagonal
π(N) vs N / ln N  —  the prime number theorem π(N) =  ·  N/ln N =  ·  ratio = (exact — sieve-counted, not estimated)
the field

a diagonal
Hover the field; click any cell to snap to its 45° diagonal, or drag to sweep. ←/→ steps the four principal arms.

what you're seeing
Every integer 1, 2, 3, … laid out in a square spiral; only the primes are lit. The dots fall onto diagonals all by themselves — and each diagonal is exactly a quadratic 4t² + bt + c. Two independent oracles — a Sieve of Eratosthenes and a from-scratch trial-division check — must agree on every number up to N, so no lit dot can lie.
the punchlines
The brightest diagonal is Euler's n²−n+41: it lands on a prime for n = 0, 1, 2, … all the way to 40 — forty-one primes in a row, an unbroken gold streak. Then at n = 41 it gives 41² = 1681, its first composite. Pick it and watch the streak run, and break, exactly there.
The running count of lit cells is π(N) — exact, sieve-counted. As N grows it tracks N / ln N, the Prime Number Theorem's estimate; the ratio tightens toward 1. The primes thin out, but never quite stop.

The number-theory sibling of The Best Rational.