ulam snake

Introduction

I've had a deep interest in the unpredictable pattern of prime numbers for awhile, and I wished to make a visual art project that displayed their randomness in a unique way. I've done basic data visualization of prime numbers in the past, specifically tallying the difference between primes and how frequent each numerical amount of gap occurs (see this "sexy" wiki article). Before I hop into the explanation of my small project, there's some prior knowledge about another visual representation of prime numbers that needs some introduction, as what I created is heavily inspired by it.

What is an Ulam spiral?

Stantislaw Ulam, Polish-American mathematician, was in need to kill some time. Allegedly out of boredom, Ulam constructed an outward-expanding pattern of integers, in a "spiral" formation, that started at 1 and incremented upwards to his desired amount. Whilst doing so, he marked all of the integers that were prime. With enough numbers to sample, noticeable trends begin to emerge after all prime numbers are marked in the spiral. Large concentrations of prime numbers can be seen along diagonal paths, or so called "highways", that can be used to predict the existence of other primes beyond the generated set of integers.

Ok, now what's an Ulam snake?

Instead of marking the location of prime numbers alone, you would instead have the occurence of primes determine the shape of the path itself. The snake starts off by travelling in a constant direction counting up from 1 like before. However, once a prime is encountered, the direction of the snake rotates at a right angle. So if the snake were marching initially to the right and came across a 7, the snake would be moving down on 8. Repeat the pattern until the desired limit of numbers is met.

ulam_example

Here is an example of a close up version

ulam_large_example

Longer instance with over 10,000 iterations

Some Code Snippets (Coming Soon)

The following will have a few sections of how the program generates the image. I'll include the primary class/helper functions used to store data of the ulam snake itself. I'm looking to for a good way to style my code snippets with syntax highlighting, while not needing the use of external javascript files. I'd like to go a bit more in-depth on my methodology of creating the program, which will hopefully be explained coherent enough for someone to use it.

social distance simulator

* * * Coming Soon * * *