login
This site is supported by donations to The OEIS Foundation.

 

Logo


Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A174344 List of x-coordinates of point moving in clockwise square spiral. 17
0, 1, 1, 0, -1, -1, -1, 0, 1, 2, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2, -1, 0, 1, 2, 3, 3, 3, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3, -3, -3, -3, -3, -2, -1, 0, 1, 2, 3, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 1, 0, -1, -2, -3, -4, -4, -4, -4, -4, -4, -4, -4, -4, -3, -2 (list; graph; refs; listen; history; text; internal format)
OFFSET

1,10

COMMENTS

Also, list of x-coordinates of point moving in counterclockwise square spiral.

This spiral, in either direction, is sometimes called the "Ulam spiral", but "square spiral" is a better name. (Ulam looked at the positions of the primes, but of course the spiral itself must be much older.) - N. J. A. Sloane, Jul 17 2018

Graham, Knuth and Patashnik give an exercise and answer on mapping n to square spiral x,y coordinates, and back x,y to n.  They start 0 at the origin and first segment North so their y(n) is a(n+1).  In their table of sides, it can be convenient to take n-4*k^2 so the ranges split at -m, 0, m. - Kevin Ryde, Sep 16 2019

REFERENCES

Ronald L. Graham, Donald E. Knuth, Oren Patashnik, Concrete Mathematics, Addison-Wesley, 1989, chapter 3, Integer Functions, exercise 40 page 99 and answer page 498.

LINKS

Peter Kagey, Table of n, a(n) for n = 1..10000

S. Mustonen, Ulam spiral in color

Hugo Pfoertner, Visualization of spiral using Plot 2, May 29 2018

Aaron Snook, Augmented Integer Linear Recurrences, Thesis, 2012.

FORMULA

a(1) = 0, a(n) = a(n-1) + sin(mod(floor(sqrt(4*(n-2)+1)),4)*Pi/2). For a corresponding formula for the y-coordinate, replace sin by cos. - Seppo Mustonen, Aug 21 2010 with correction by Peter Kagey, Jan 24 2016

EXAMPLE

Here is the beginning of the clockwise square spiral. Sequence gives x-coordinate of the n-th point.

.

  20--21--22--23--24--25

   |                   |

  19   6---7---8---9  26

   |   |           |   |

  18   5   0---1  10  27

   |   |       |   |   |

  17   4---3---2  11  28

   |               |   |

  16--15--14--13--12  29

                       |

  35--34--33--32--32--30

.

MAPLE

fx:=proc(n) option remember; local k; if n=1 then 0 else

k:=floor(sqrt(4*(n-2)+1)) mod 4;

fx(n-1) + sin(k*Pi/2); fi; end;

[seq(fx(n), n=1..120)]; # Based on Seppo Mustonen's formula. - N. J. A. Sloane, Jul 11 2016

MATHEMATICA

a[n_]:=a[n]=If[n==0, 0, a[n-1]+Sin[Mod[Floor[Sqrt[4*(n-1)+1]], 4]*Pi/2]]; Table[a[n], {n, 0, 50}] (* Seppo Mustonen, Aug 21 2010 *)

PROG

(PARI) L=0; d=1;

for(r=1, 9, d=-d; k=floor(r/2)*d; for(j=1, L++, print1(k, ", ")); forstep(j=k-d, -floor((r+1)/2)*d+d, -d, print1(j, ", "))) \\ Hugo Pfoertner, Jul 28 2018

(PARI) a(n) = n--; my(m=sqrtint(n), k=ceil(m/2)); n -= 4*k^2; if(n<0, if(n<-m, k, -k-n), if(n<m, -k, n-3*k)); \\ Kevin Ryde, Sep 16 2019

(PARI) apply( A174344(n)={my(m=sqrtint(n-=1), k=m\/2); if(n < 4*k^2-m, k, 0 > n -= 4*k^2, -k-n, n < m, -k, n-3*k)}, [1..99]) \\ M. F. Hasler, Oct 20 2019

(Julia)

function SquareSpiral(len)

    x, y, i, j, N, n, c = 0, 0, 0, 0, 0, 0, 0

    for k in 0:len-1

        print("$x, ") # or print("$y, ") for A268038.

        if n == 0

            c += 1; c > 3 && (c =  0)

            c == 0 && (i = 0; j =  1)

            c == 1 && (i = 1; j =  0)

            c == 2 && (i = 0; j = -1)

            c == 3 && (i = -1; j = 0)

            c in [1, 3] && (N += 1)

            n = N

        end

        n -= 1

        x, y = x + i, y + j

end end

SquareSpiral(75) # Peter Luschny, May 05 2019

CROSSREFS

Cf. A180714. A268038 (or A274923) gives sequence of y-coordinates.

The (x,y) coordinates for a point sweeping a quadrant by antidiagonals are (A025581, A002262). - N. J. A. Sloane, Jul 17 2018

See A296030 for the pairs (A174344(n), A274923(n)). - M. F. Hasler, Oct 20 2019

Sequence in context: A124752 A293730 A318722 * A049241 A321858 A230415

Adjacent sequences:  A174341 A174342 A174343 * A174345 A174346 A174347

KEYWORD

sign,changed

AUTHOR

Nikolas Garofil (nikolas(AT)garofil.be), Mar 16 2010

EXTENSIONS

Link corrected by Seppo Mustonen, Sep 05 2010

Definition clarified by N. J. A. Sloane, Dec 20 2012

STATUS

approved

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recent
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified October 23 14:29 EDT 2019. Contains 328345 sequences. (Running on oeis4.)