Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Get the coordinates of the points on a square spiral with sides parallel to the axes
| ResourceFunction["SquareSpiralPoints"][n] gives the list of coordinate pairs on a square spiral with n sides starting at the origin. | 
Here are the points on the first four sides of the spiral:
| In[1]:= | ![ResourceFunction["SquareSpiralPoints"][4]](https://www.wolframcloud.com/obj/resourcesystem/images/1e1/1e1f4028-3b61-4921-b8cf-bb494b8ee7db/6855e37154746ec6.png) | 
| Out[1]= |  | 
This shows the sequence of points in order on the first six sides:
| In[2]:= | ![With[{s = ResourceFunction["SquareSpiralPoints"][6]}, Graphics[{{Pink, PointSize[.03], Point[s]}, Arrow@Partition[s, 2, 1]}]]](https://www.wolframcloud.com/obj/resourcesystem/images/1e1/1e1f4028-3b61-4921-b8cf-bb494b8ee7db/36528b2298ab723a.png) | 
| Out[2]= |  | 
Forty black sides with 20 red sides overlaid:
| In[3]:= | ![Graphics[{Line@ResourceFunction["SquareSpiralPoints"][40], Red, Line@ResourceFunction["SquareSpiralPoints"][20]}]](https://www.wolframcloud.com/obj/resourcesystem/images/1e1/1e1f4028-3b61-4921-b8cf-bb494b8ee7db/7a3082d18af83ced.png) | 
| Out[3]= |  | 
The number of points in n sides:
| In[4]:= | ![Length@ResourceFunction["SquareSpiralPoints"]@# & /@ Range[0, 10]](https://www.wolframcloud.com/obj/resourcesystem/images/1e1/1e1f4028-3b61-4921-b8cf-bb494b8ee7db/69e22e4795631e9e.png) | 
| Out[4]= |  | 
| In[5]:= | ![Table[Floor[(n + 1)^2/4] + 1, {n, 0, 10}]](https://www.wolframcloud.com/obj/resourcesystem/images/1e1/1e1f4028-3b61-4921-b8cf-bb494b8ee7db/27bc2c668bbf8c8e.png) | 
| Out[5]= |  | 
This finds the coordinate pairs that are a prime distance along the square spiral:
| In[6]:= | ![UlamSquareSpiralPoints[n_] := ResourceFunction["SquareSpiralPoints"][n][[
  Prime@Range@PrimePi[Floor[(n + 1)^2/4] + 1] ]]](https://www.wolframcloud.com/obj/resourcesystem/images/1e1/1e1f4028-3b61-4921-b8cf-bb494b8ee7db/1ebb3112772b0399.png) | 
The larger points correspond to the primes 2, 3, 5, 7, 11, 13:
| In[7]:= | ![With[{n = 6}, Graphics[{{LightGray, Line@ResourceFunction["SquareSpiralPoints"]@n},
    Point@ResourceFunction["SquareSpiralPoints"]@n, PointSize[.08], Point@UlamSquareSpiralPoints@n}, ImageSize -> 100]]](https://www.wolframcloud.com/obj/resourcesystem/images/1e1/1e1f4028-3b61-4921-b8cf-bb494b8ee7db/25800df3b1cbcd29.png) | 
| Out[7]= |  | 
About 12% of the numbers up to 10101 are prime:
| In[8]:= | ![With[{n = 200}, Floor[(n + 1)^2/4] + 1]](https://www.wolframcloud.com/obj/resourcesystem/images/1e1/1e1f4028-3b61-4921-b8cf-bb494b8ee7db/712f738891cd598e.png) | 
| Out[8]= |  | 
| In[9]:= |  | 
| Out[9]= |  | 
Here are the first 1240 primes plotted along the square spiral:
| In[10]:= |  | 
| Out[10]= |  | 
About 11% of the numbers to 10101 are lucky:
| In[11]:= | ![ResourceFunction["LuckyNumbers"]@10101 // Length](https://www.wolframcloud.com/obj/resourcesystem/images/1e1/1e1f4028-3b61-4921-b8cf-bb494b8ee7db/7c75e917a97e848b.png) | 
| Out[11]= |  | 
This finds the coordinate pairs that are at lucky number distances along the square spiral:
| In[12]:= | ![LuckySquareSpiralPoints[n_] := ResourceFunction["SquareSpiralPoints"][n][[
   ResourceFunction["LuckyNumbers"][Floor[(n + 1)^2/4] + 1]
   ]]](https://www.wolframcloud.com/obj/resourcesystem/images/1e1/1e1f4028-3b61-4921-b8cf-bb494b8ee7db/0633d6a246eded73.png) | 
Here are the first 1130 lucky numbers plotted along the square spiral:
| In[13]:= |  | 
| Out[13]= |  | 
Wolfram Language 11.3 (March 2018) or above
This work is licensed under a Creative Commons Attribution 4.0 International License