Overview
OEIS A278299 asks for the fewest grid squares you need to color with n colors so that every color sits edge-to-edge with every other color at least once. The answers are hard to pin down: until 2026, only a(2) through a(11) were known exactly. This page is about the part I worked on.
- New terms
- 4a(19)–a(22), March and October 2026
- Proved by my SAT search
- a(21) = 116Previously only 116 ≤ a(21) ≤ 117
- Also settled
- a(22) = 132Example coloring meets the lower bound
- Bounds posted
- a(27) ≤ 195Plus bounds for a(23)–a(26)
01 The problem
Make every color touch every other color
Take n colors, numbered 1 to n. Color some connected squares of graph paper (a polyomino) so that, for every pair of different colors, at least one square of the first shares an edge with a square of the second. Corners don’t count. a(n) is the smallest number of squares that can do it.
For four colors there are six pairs to cover, and six squares are enough: in the shape on the right, the top 1 touches 4 and 3, that 4 touches 2, the left 4 touches 3, 3 touches 2, and 2 touches the bottom 1. Five squares can’t do it, so a(4) = 6.
Kagey’s Square Game turns this into a puzzle: you click numbers onto a grid, it marks pairs that repeat in red, and a valid grid you submit becomes an upper bound for the sequence. Kagey traces the idea to a ≠ b ≠ c ≠ a written on the board in a linear algebra class; the one-dimensional version is a solved problem, and Alec Jones suggested the two-dimensional one.
02 Why it’s hard
A huge search with a bound to beat
Two things have to be chosen at once: the shape, and the color of every square. For n = 22 and a fixed 132-square shape there are 22132, about 10177, ways to color it, and the number of possible shapes grows exponentially too. Nobody checks those one by one.
What makes progress possible is a lower bound. Peter Exley gave the one in the entry:
a(n) ≥ max( ⌊(n2 + n + 5)/4⌋, n·⌈(n − 1)/4⌉ )
Edge bound
Each of the n(n−1)/2 pairs needs its own shared edge. A polyomino with k squares and perimeter P has (4k − P)/2 internal edges, and compact shapes have the smallest perimeter, so k can’t be too small. The difference between internal edges and pairs is the slack: how many edges can be wasted on repeats.
Contact bound
Each color has to touch n − 1 others, and a square has at most four neighbors, so every color needs at least ⌈(n − 1)/4⌉ squares. For n = 22 that is 6 squares per color, 132 in all.
A lower bound settles the “nothing smaller works” half of a proof. If you can then show one coloring that hits the bound exactly, the value is proved. The hard part is finding that coloring when the slack is close to zero, or proving none exists.
03 Approach 1
Parallel simulated annealing
My first tool was a heuristic search, written in C++17 with OpenMP. It works on a score: the number of color pairs that don’t touch yet. Zero means a valid coloring.
- Start random. Grow a random connected shape of k squares and fill it with every color at least once plus random extras.
- Make a small change. Move one square to another spot on the edge of the shape, swap the colors of two squares, or recolor one square.
- Accept or undo. Keep any change that doesn’t make the score worse. Keep a worse one with probability e−Δ/T, where the temperature T cools geometrically from 5 to 0.01, so the search can climb out of dead ends early and settles down later.
- Run many at once. Each thread runs its own independent attempts under dynamic scheduling. The first thread to reach zero sets an atomic flag and the rest stop; if none succeeds, k goes up by one.
A second version replaced the hash map with a flat grid array, updated the score incrementally instead of recounting every edge, kept shapes connected when squares move, and added parallel tempering, where threads at different temperatures swap configurations. I then wrote a CUDA annealer that gives each candidate shape its own GPU thread block, with the threads counting edges cooperatively.
The runs went to the BYU supercomputer as SLURM batch jobs. The job script rebuilds the binary whenever it lands on a node with a different CPU instruction set, since it is compiled with -march=native.
04 Approach 2
Exact search with a SAT solver
A SAT solver takes a long list of true/false constraints and either finds values that satisfy all of them or proves that none exist. To use one here, I fix a candidate shape and translate the question into Boolean variables that say which color each square gets, with clauses saying that each square gets exactly one color and that every pair of colors meets across at least one shared edge. Candidate shapes are enumerated by perimeter, which the edge bound limits.
The search for n = 21 at 116 squares came back satisfiable: the solver returned a complete coloring. Since 116 is the lower bound for n = 21, that one example proves a(21) = 116. The same work settled a(22) = 132, which is exactly the contact bound, with the coloring in Fig. 2. Each returned coloring is checked by a separate verifier that shares no code with the encoder. Ryan Lee’s SAT search for a(20) = 106 worked the same way: the example it returned meets the bound.
I built the SAT tooling in Python with the CaDiCaL solver, with help from Claude Code.
05 Results
The new terms and bounds
| n | a(n) | Lower bound | Status | Credit in the entry |
|---|---|---|---|---|
| 19 | 96 | 96 | Proved; example meets the edge bound | Nels Buhrley and Ryan Lee |
| 20 | 106 | 106 | Proved; Ryan Lee’s SAT search | Nels Buhrley and Ryan Lee |
| 21 | 116 | 116 | Proved; my SAT search | Nels Buhrley |
| 22 | 132 | 132 | Proved; example meets the contact bound | Nels Buhrley |
| 23 | 139–141 | 139 | Open | Bounds: Nels Buhrley |
| 24 | 151–154 | 151 | Open | Bounds: Nels Buhrley |
| 25 | 163–167 | 163 | Open | Bounds: Nels Buhrley; 167 by Dmitry Kamenetsky |
| 26 | 182 | 182 | In comments; meets the contact bound | Nels Buhrley |
| 27 | 190–195 | 190 | Open | Bounds: Nels Buhrley |
The data section of the entry stops at a(22) because a(23) is still open; a(26) is recorded in the comments.
Fig. 2 as a table
| Row 1 | 15 | 20 | 6 | 1 | 13 | 19 | 11 | 2 | 4 | 6 | 5 | 17 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Row 2 | 18 | 11 | 21 | 4 | 17 | 3 | 5 | 20 | 10 | 18 | 8 | 10 |
| Row 3 | 2 | 15 | 9 | 11 | 6 | 22 | 19 | 1 | 12 | 5 | 16 | 4 |
| Row 4 | 3 | 13 | 7 | 8 | 13 | 9 | 16 | 21 | 3 | 7 | 15 | 5 |
| Row 5 | 6 | 14 | 11 | 3 | 4 | 19 | 6 | 2 | 16 | 18 | 3 | 14 |
| Row 6 | 9 | 8 | 22 | 20 | 8 | 2 | 10 | 19 | 12 | 14 | 10 | 9 |
| Row 7 | 20 | 17 | 11 | 16 | 10 | 5 | 1 | 8 | 6 | 15 | 21 | 17 |
| Row 8 | 19 | 15 | 1 | 17 | 22 | 21 | 18 | 20 | 7 | 10 | 13 | 12 |
| Row 9 | 18 | 4 | 9 | 2 | 7 | 19 | 17 | 14 | 12 | 11 | 22 | 18 |
| Row 10 | 13 | 20 | 12 | 22 | 4 | 14 | 7 | 1 | 2 | 13 | 5 | 9 |
| Row 11 | 7 | 21 | 8 | 15 | 12 | 21 | 16 | 22 | 14 | 16 | 1 | 3 |
Fig. 3 as a table
| Row 1 | 12 | 1 | 6 | 2 | 18 | 11 | 17 | 18 | 9 | 13 | 16 | 18 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Row 2 | 19 | 11 | 3 | 17 | 6 | 10 | 12 | 13 | 6 | 19 | 9 | 10 |
| Row 3 | 7 | 9 | 2 | 7 | 4 | 14 | 18 | 7 | 12 | 14 | 3 | 19 |
| Row 4 | 10 | 17 | 16 | 8 | 3 | 5 | 19 | 1 | 9 | 15 | 10 | 8 |
| Row 5 | 2 | 14 | 7 | 6 | 15 | 1 | 17 | 13 | 14 | 8 | 4 | 9 |
| Row 6 | 4 | 11 | 15 | 16 | 19 | 4 | 5 | 10 | 1 | 2 | 13 | 5 |
| Row 7 | 17 | 8 | 18 | 5 | 2 | 15 | 12 | 16 | 3 | 12 | 11 | 6 |
| Row 8 | 15 | 13 | 3 | 7 | 11 | 5 | 8 | 1 | 18 | 4 | 16 | 14 |
06 Takeaways
What I learned, and the limits
- Pick the tool by the slack. When a size leaves plenty of room for repeated pairs, annealing finds colorings quickly. When the slack is near zero (the a(19) coloring has exactly one spare edge), an exact search is the better bet.
- A bound turns an example into a proof. All four new values sit exactly on Exley’s lower bound, so each one is proved by a single verified coloring. That is also the limit of what I have shown: none of these proofs needed the solver to rule a size out.
- The open cases are harder. For a(23), a(24), a(25) and a(27) the gap between bounds is 2 to 5 squares. Closing it means either a coloring on the bound or proving that every shape of that size fails, which is far more expensive.
- Check results independently. A verifier that shares no code with the search is cheap insurance before submitting anything to the OEIS.
Links
- OEIS A278299 The entry, with data, comments, bounds and diagrams
- Square Game Peter Kagey’s puzzle behind the sequence
- My Favorite Sequences: “Not Equal” Grid Kagey’s blog post on the problem’s history and open questions
- Personal-Projects on GitHub My simulated-annealing search (“Grid Srtructure Finder”)