Skip to main content
replaced http://math.stackexchange.com/ with https://math.stackexchange.com/
Source Link

#Prime Spiral

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 n is composite: Go straight in the same direction to place n+1
  • If n is prime: Turn right to place n+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)

#Prime Spiral

This challenge was inspired by this question on math.SE by @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 n is composite: Go straight in the same direction to place n+1
  • If n is prime: Turn right to place n+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 (by @Wojowu)

#Prime Spiral

This challenge was inspired by this question on math.SE by @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 n is composite: Go straight in the same direction to place n+1
  • If n is prime: Turn right to place n+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 (by @Wojowu)

deleted 1 character in body
Source Link
mbomb007
  • 23.6k
  • 27
  • 42

#Prime Spiral

This challenge was inspired by this question on math.SE by @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 ana 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 n is composite: Go straight in the same direction to place n+1
  • If n is prime: Turn right to place n+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 (by @Wojowu)

#Prime Spiral

This challenge was inspired by this question on math.SE by @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 an 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 n is composite: Go straight in the same direction to place n+1
  • If n is prime: Turn right to place n+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 (by @Wojowu)

#Prime Spiral

This challenge was inspired by this question on math.SE by @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 n is composite: Go straight in the same direction to place n+1
  • If n is prime: Turn right to place n+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 (by @Wojowu)

added 50 characters in body
Source Link
flawr
  • 44.1k
  • 42
  • 43

#Prime Spiral

This challenge was inspired by this question on math.SE by @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 an 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 n is composite: Go straight in the same direction to place n+1
  • If n is prime: Turn right to place n+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)

#Prime Spiral

This challenge was inspired by this question on math.SE by @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 an 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 n is composite: Go straight in the same direction to place n+1
  • If n is prime: Turn right to place n+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 (by @Wojowu)

#Prime Spiral

This challenge was inspired by this question on math.SE by @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 an 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 n is composite: Go straight in the same direction to place n+1
  • If n is prime: Turn right to place n+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 (by @Wojowu)

added 54 characters in body
Source Link
flawr
  • 44.1k
  • 42
  • 43
Loading
added 723 characters in body
Source Link
flawr
  • 44.1k
  • 42
  • 43
Loading
Source Link
flawr
  • 44.1k
  • 42
  • 43
Loading