Watch the evolution of the Ulam Spiral

In 1963, Stanislaw Ulam was attending a talk, during which he became bored. He began to doodle on some paper, but his doodling soon gained some purpose. He drew a grid, and started labeling the positions in his grid with numbers, starting in the center and spiraling outward.

After a bit of this, he circled the prime numbers in his spiral. He noticed a remarkable pattern. Do you see it?

111112113114115116117118119120121
11073747576777879808182
10972434445464748495083
10871422122232425265184
10770412078910275285
10669401961211285386
10568391854312295487
10467381716151413305588
10366373635343332315689
10265646362616059585790
101100999897969594939291

The prime numbers seem to cluster along diagonal lines. This pattern persists remarkably even if the spiral is quite different from this one. See this Wikipedia article for a circular version and this page on Wolfram's site for a hexagonal one.

Actually, there are lots of patterns in this grid. Here is another one:



Ulam was a scientist at the Los Alamos National Laboratory, where he had access to some of the best computers available in the world at that time. When he returned home from the trip during which he had made this discovery, he programmed a computer to draw larger grids, to see if the pattern persisted.

Here is what he saw:


(Watch in the section below.)

 
 

Ulam's Spiral

Looks like your browser doesn't support the canvas element. Too bad.

Size of spiral:
pixels

Size of integer spots:
pixels square

Speed (integers):
per second





It seems surprising that the prime numbers might cluster along diagonals in a matrix like this one. But if you think another way, it is perhaps less surprising:
Primes are simply numbers that are NOT composite, right? On a grid like Ulam's, it is actually not surprising to find that the composite numbers align themselves along gridlines; this is probably what you would expect. The prime numbers are what is left when the composite numbers are eliminated, so they go in the ‘holes’ left after the composites are all placed. Seems like the holes might look like they are following gridlines too, then, right?

Well, now that I've learned how to do that, I'm strongly tempted to update or redo my Mandelin app. I always wanted it to update in real-time, so that you could watch the details unfold. A canvas-javascript-based Mandelbrot set app seems like a pretty natural way to do that.