The Erdős unit distance problem sounds like a rainy-afternoon puzzle. Scatter some pins on a board and count how many pairs sit exactly one inch apart. Paul Erdős asked it in 1946 and made a guess about the answer. That guess stood for eighty years, until an AI model knocked it over this May.

Want to try it yourself? The query that drew this picture is further down, ready to copy into SSMS.

The Puzzle, With Pins and String

Picture a corkboard, a box of pins and a spool of red string. Cut every piece of string to exactly the same length. Now push in some pins, and stretch a string between every pair that sits exactly that far apart.

The question sounds simple. With a hundred pins, or a million, what is the largest number of strings you can fit? You can place the pins anywhere you like. Every string has to be exactly one unit long, though, not almost.

Small cases are fun to play with. Three pins in an equilateral triangle give three strings. Four pins in a diamond of two such triangles give five. Seven pins, a regular hexagon around a center pin, give twelve.

Three pin and string diagrams: an equilateral triangle with 3 pins and 3 strings, two triangles sharing a side with 4 pins and 5 strings, and a regular hexagon around a center pin with 7 pins and 12 strings

The strings grow faster than the pins, but not by a lot. Erdős wanted to know how much faster they can possibly grow. It became one of the best-known open questions in geometry.

Erdős’s Grid Trick

Erdős started with the most boring arrangement possible: a square grid of pins. The clever part was choosing the length of the string. You don’t pick the grid spacing. You pick a length that lots of grid steps share.

Take 65. You can write it as a sum of two squares in two ways: 1² + 8² and 4² + 7². Each way lands on eight grid points at the same distance. So a pin in the middle of the grid gets 16 strings.

A square grid of pins with 16 red strings running from the center pin to the 16 grid points exactly the square root of 65 away, because 65 equals 1 squared plus 8 squared and 4 squared plus 7 squared

Some numbers can be written as a sum of two squares in many ways. Pick one of those, shrink the grid until that length is exactly 1, and the strings pile up. With this idea, Erdős got a count that grows a whisker faster than the number of pins.

Then came the famous guess. Erdős believed the grid was close to the best anyone could do. No clever arrangement would beat it by more than that whisker.

Checking Erdős in SQL Server

I’m a database person, so I didn’t want to take Erdős’s word for it. Pins are rows, and a string is a self-join where the distance comes out right. This query builds a 10 by 10 grid of pins and counts which lengths connect the most pairs.

WITH n AS (SELECT v FROM (VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) AS t(v)),
     pins AS (SELECT a.v AS x, b.v AS y FROM n AS a CROSS JOIN n AS b)
SELECT TOP (5)
       (p.x - q.x) * (p.x - q.x) + (p.y - q.y) * (p.y - q.y) AS squared_length,
       COUNT(*) AS pairs
FROM pins AS p
JOIN pins AS q
  ON p.x < q.x OR (p.x = q.x AND p.y < q.y)
GROUP BY (p.x - q.x) * (p.x - q.x) + (p.y - q.y) * (p.y - q.y)
ORDER BY pairs DESC;

It works with squared lengths, so everything stays in whole numbers. This is what it returned on SQL Server 2025:

squared_length  pairs
--------------  -----
5               288
25              268
10              252
13              224
17              216

The winner surprised me. Pins exactly 1 apart make only 180 pairs, which doesn’t even crack the top five. The length √5 connects 288 pairs, and length 5 connects 268. On a 40 by 40 grid, √65 comes out on top with 9,744 pairs.

SQL Server also has a spatial side, and it fits this puzzle nicely. Every pin can be a geometry point, and STDistance measures the gap between any two of them. This version builds the 40 by 40 grid and counts pairs exactly √65 apart.

DECLARE @length float = SQRT(65.0);
WITH n AS (SELECT TOP (40) ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) - 1 AS v FROM sys.all_objects),
     pins AS (SELECT a.v AS x, b.v AS y, geometry::Point(a.v, b.v, 0) AS pin FROM n AS a CROSS JOIN n AS b)
SELECT COUNT(*) AS strings
FROM pins AS p
JOIN pins AS q
  ON p.x < q.x OR (p.x = q.x AND p.y < q.y)
WHERE ABS(p.pin.STDistance(q.pin) - @length) < 0.000001;
strings
-------
9744

Same answer, found a different way. It checked all 1,279,200 pairs of pins in about four seconds on my machine. Notice the tolerance in the WHERE clause. Distances come back as floating point numbers, and SQL Server, like me, isn’t great at “exactly”.

Now the fun part. This query asks SQL Server to draw the grid trick itself. It returns four shapes: the 16 strings, all 361 pins, the 16 pins the strings reach, and the center pin. Run it in SSMS and open the Spatial results tab.

WITH n AS (
  SELECT v FROM (VALUES (-9),(-8),(-7),(-6),(-5),
    (-4),(-3),(-2),(-1),(0),(1),(2),(3),(4),
    (5),(6),(7),(8),(9)) AS t(v)),
pins AS (
  SELECT geometry::Point(a.v, b.v, 0) AS pin
  FROM n AS a CROSS JOIN n AS b),
hits AS (
  SELECT pin FROM pins
  WHERE ABS(pin.STDistance(geometry::Point(0, 0, 0))
            - SQRT(65.0)) < 0.000001)
SELECT 'strings' AS part,
       geometry::UnionAggregate(geometry::Point(0, 0, 0)
         .ShortestLineTo(pin).STBuffer(0.08)) AS shape
FROM hits
UNION ALL
SELECT 'pins', geometry::UnionAggregate(pin) FROM pins
UNION ALL
SELECT 'the 16 pins',
       geometry::UnionAggregate(pin.BufferWithTolerance(0.3, 0.01, 0))
FROM hits
UNION ALL
SELECT 'center pin',
       geometry::Point(0, 0, 0).BufferWithTolerance(0.4, 0.01, 0);

The picture at the top of this post is the real Spatial results tab from my SSMS. Nothing in it is placed by hand: the WHERE clause finds the 16 pins that sit √65 from the center. STBuffer thickens the strings, and UnionAggregate merges them into one shape, so SSMS gives them one color. Erdős’s trick, drawn by the same engine that runs your payroll.

One tip if you try your own drawings. My SSMS 22 truncated large shapes on the Spatial results tab. That’s why the 361 pins are plain points, not little circles. I also unticked Show grid lines to make the star stand out.

Where This Shows Up in the Real World

Nobody sells software that solves Erdős’s puzzle. The spatial skills we used show up everywhere, though. “Which stores are near this customer?” is the same pins-and-distance idea, with a map instead of a corkboard.

For real locations, use geography instead of geometry. With SRID 4326, STDistance returns meters, so “within 5 kilometers” is a plain WHERE clause. Real apps ask for a radius, not an exact distance, which is a relief for everyone.

Delivery apps match addresses to service areas with a spatial join. Fleet tools check whether a truck’s last position sits inside a depot boundary. Both are points and shapes, the same toolkit as this post.

One warning from the performance side of my life. Our all-pairs query is great for learning and slow at scale, because pairs grow with the square of the pins. For real data, give SQL Server a spatial index and a query shape that can use it.

The Floor and the Ceiling

For decades, mathematicians pushed on the question from both sides. The grid gave a floor, a count you can always reach. In 1984, Joel Spencer, Endre Szemerédi and William Trotter proved a ceiling. With n pins, you never get more than a fixed multiple of n to the power 4/3.

That left a gap. The floor sat a hair above n to the power 1, and the ceiling sat at 4/3. For about forty years, nobody moved either one in a way that mattered.

What the AI Found

On May 20, 2026, OpenAI announced that one of its internal reasoning models had broken Erdős’s guess. The model was given the problem and came back with a counterexample, written up in about 125 pages. OpenAI says the model produced the proof on its own.

The model proved you can beat the grid by a real power of n, without saying how big. Mathematician Will Sawin worked out a number the same day: more than n to the power 1.014 strings. The grid’s extra power shrinks toward zero as n grows. That 0.014 stays put, so the new count wins in the end.

A number line of exponents from 1.00 to 1.40 showing Erdős's guess near 1, the 2026 construction at 1.014, the 1984 ceiling at 4/3, and the still unknown band between 1.014 and 4/3

The surprise was where the idea came from. Instead of cleverer geometry, it reached into algebraic number theory, which studies number systems beyond the ordinary integers. Among other ideas, it leaned on a 1964 result by Evgeny Golod and Igor Shafarevich. That result says certain towers of those number systems go on forever.

It’s a geometry puzzle solved with a tool from a different aisle of the hardware store. Nobody had made that tool work on this problem before.

Is It Official?

This one didn’t need a committee. Nine mathematicians published a checked, human-readable version of the counterexample, and new papers already build on it. As far as mathematicians are concerned, Erdős’s guess is wrong.

The real answer is still open, though. The exact growth rate sits between the new constructions and the 4/3 ceiling, and nobody knows where. Compare that with the Navier-Stokes announcement from this month, which is still waiting for its checks. Or with Fermat’s margin note, which took other people 358 years to finish and check.

What I Take From It

A cork board crowded with brass pins and red strings all cut to the same length, with a small card pinned at the edge reading EXACTLY 1

I’m not a mathematician. I’m a database consultant who spent a Saturday making SQL Server count pins. It was the most fun I’ve had with a spatial query in years.

That’s what I love about a problem like this. A kid can follow the question with pins and string. A DBA can test the old trick with a self-join. The answer still needed a tool from the far end of the math building.

Checking a result like this is a skill of its own. I wrote about it in How to Check AI Fast. It’s about finding the part of an answer that holds everything else up. The nine mathematicians did exactly that with 125 pages.

The essay is one of thirty in my book AI: Nobody’s in There. But we’re still in here. All of them are free to read online, and the paperback is on Amazon.

Next time you’re bored on a Saturday, build a grid of pins in SQL Server. It’s more fun than it sounds.

A great puzzle is not a rainy-afternoon toy, it is an eighty-year invitation.

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.

Share.
Leave A Reply