login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A274923 List of y-coordinates of point moving in counterclockwise square spiral. 66
0, 0, 1, 1, 1, 0, -1, -1, -1, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2, -2, -1, 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3, -3, -3, -3, -3, -3, -2, -1, 0, 1, 2, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 1, 0, -1, -2, -3, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -3, -2, -1, 0 (list; graph; refs; listen; history; text; internal format)
OFFSET
1,13
COMMENTS
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 a(n) is their -x(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 17 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
MAPLE
fy:=proc(n) option remember; local k; if n=1 then 0 else
k:=floor(sqrt(4*(n-2)+1)) mod 4;
fy(n-1) - cos(k*Pi/2); fi; end;
[seq(fy(n), n=1..120)]; # Based on Seppo Mustonen's formula in A174344.
MATHEMATICA
a[n_] := a[n] = If[n == 0, 0, a[n-1] - Cos[Mod[Floor[Sqrt[4*(n-1)+1]], 4]* Pi/2]];
Table[a[n], {n, 0, 100}] (* Jean-François Alcover, Jun 11 2018, after Seppo Mustonen *)
PROG
(PARI) L=1; 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, 3*k+n, k), if(n<m, k-n, -k)); \\ Kevin Ryde, Sep 17 2019
(PARI) apply( A274923(n)={my(m=sqrtint(n-=1), k=m\/2); if(m <= n -= 4*k^2, -k, n >= 0, k-n, n >= -m, k, 3*k+n)}, [1..99]) \\ M. F. Hasler, Oct 20 2019
CROSSREFS
Cf. A268038 (negated), A317186 (indices of 0's).
Cf. A174344 (x-coordinates).
The (x,y) coordinates for a point sweeping a quadrant by antidiagonals are (A025581, A002262). - N. J. A. Sloane, Jul 17 2018
A296030 gives pairs (x = A174344(n), y = a(n)). - M. F. Hasler, Oct 20 2019
The diagonal rays of the square spiral (coordinates (+-n,+-n)) are: A002939 (2n(2n-1): 0, 2, 12, 30, ...), A016742 = (4n^2: 0, 4, 16, 36, ...), A002943 (2n(2n+1): 0, 6, 20, 42, ...), A033996 = (4n(n+1): 0, 8, 24, 48, ...). - M. F. Hasler, Oct 31 2019
Sequence in context: A226456 A343642 A268038 * A249071 A231713 A340945
KEYWORD
sign,easy
AUTHOR
N. J. A. Sloane, Jul 11 2016
STATUS
approved

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

License Agreements, Terms of Use, Privacy Policy. .

Last modified April 25 08:27 EDT 2024. Contains 371964 sequences. (Running on oeis4.)