Monday, October 19, 2020

A 2D walk generated by primes

Consider starting at (0,0) on the plane and as we enumerate the primes p, except for 2 and 5, we take a step in the E, N, W, S direction depending on whether the last decimal digit of p is 1, 3, 7, 9 respectively.

The resulting 2D walk looks quite interesting. The first 200,000 steps looks like this:


The Python code used to generate this plot can be found here.
Using a different correspondence of last digit to directions, we get different, but qualitatively similar plots.
For instance (1->W, 3->E, 7->S, 9->N) gives us:
Overall, they seem more clustered and dense that a 2D random walk.