#Prime Spiral
primescode-golfgraphical-output
This challenge was inspired by this question on math.SEthis question on math.SE by @Karl@Karl
You might be familiar with the Ulam spiral. What we're doing here is similar, but a little bit different, given a positive integer N we generate an image:
On an empty equally spaced rectangular 2d grid choose an arbitrary point and place a 1 then place a 2 on the grid point to the right of the 1. Then continue as follows:
If you're at number n<N:
- If
nis composite: Go straight in the same direction to placen+1 - If
nis prime: Turn right to placen+1(overwrite, if there was another from a previous step) - Repeat this for
n:=n+1.
Now consider the grid as a pixel image that is plain white. Then colour each pixel where we placed a number on the corresponding grid point. Then choose a finite rectangle that contains all the coloured pixels, and output it as an image.
###Examples
For N=10^5 we get following output (byby @Wojowu@Wojowu)