Help with a prime number spiral which turns 90 degrees at each prime

I awoke with the following puzzle that I would like to investigate, but the answer may require some programming (it may not either). I have asked on the meta site and believe the question to be suitable and hopefully interesting for the community.

I will try to explain the puzzle as best I can then detail the questions I am interested in after.

Imagine squared paper. In one square write the number 1. Continue to write numbers from left to right (as normal) until you reach a prime. The next number after a prime should be written in the square located 90 degrees clockwise to the last. You then continue writing numbers in that direction. This procedure should be continued indefinitely.

Here is a sample of the grid:


Note that the square containing 3 also contains 15 (I couldn’t put it in without confusing the diagram. In fact some squares contain multiple entries.
I would have liked to see an expanded version of the diagram. I originally thought of shading squares that contain at least one number.

Does the square surrounded by 2,3,9,10,11,12,13,14 ever get shaded?
If so, will the whole grid ever be shaded?
Is there a maximum number of times a square can be visited? I have got to 4 times but it is easy to make mistakes by hand.
Are there any repeated patterns in the gaps?
I have other ideas but this is enough for now as I have genuinely no idea how easy or difficult this problem is.

Please forgive me for not taking it any further as it is so easy to make mistakes.
I hope this is interesting for the community and look forwards to any results.

Any questions I’ll do my best to clarify.

Side note: I observed that initially at least the pattern likes to cling to itself but I suspect it doesn’t later on.


Just for visual amusement, here are more pictures. In all cases, initial point is a large red dot.

Primes up to 105:
enter image description here

Primes up to 106:
enter image description here

Primes up to 106 starting gaps of length >6:
enter image description here

Primes up to 107 starting gaps of length >10:
enter image description here

Primes up to 108 starting gaps of length >60:
enter image description here

For anyone interested, all the images were generated using Sage and variations of the following code:

d = 1
p = 0
M = []
prim = prime_range(10^8)
diff = []
for i in range(len(prim)-1):
for k in diff:
    if k>60:
    d = -d*I
    p = p+k*d
save(list_plot(M,aspect_ratio = 1,axes = false,pointsize = 1,figsize = 20)+point((0,0),color = 'red'),'8s.png')

Source : Link , Question Author : Karl , Answer Author : Wojowu

Leave a Comment