A174344 List of x-coordinates of point moving in clockwise square spiral.
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
Offset: 1
Keywords
Examples
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 . Given the offset equal to 1, a(n) gives the x-coordinate of the point labeled n-1 in the above drawing. - _M. F. Hasler_, Nov 03 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
- Seppo Mustonen, Ulam spiral in color [Interactive web page]
- Seppo Mustonen, Ulam spiral in color [Local copy of a snapshot of the page]
- Hugo Pfoertner, Visualization of spiral using Plot 2, May 29 2018
- N. J. A. Sloane, Ulam spiral in color.
- Aaron Snook, Augmented Integer Linear Recurrences, Thesis, 2012.
- Index entries for sequences related to coordinates of 2D curves
Crossrefs
The (x,y) coordinates for a point sweeping a quadrant by antidiagonals are (A025581, A002262). - N. J. A. Sloane, Jul 17 2018
The diagonal rays are: A002939 (2*n*(2*n-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
Programs
-
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
-
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 *)
-
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
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
-
Python
# Based on Kevin Ryde's PARI script import math def A174344(n): n -= 1 m = math.isqrt(n) k = math.ceil(m/2) n -= 4*k*k if n < 0: return k if n < -m else -k-n return -k if n < m else n-3*k # David Radcliffe, Aug 04 2025
Formula
a(1) = 0, a(n) = a(n-1) + sin(floor(sqrt(4n-7))*Pi/2). For a corresponding formula for the y-coordinate, replace sin with cos. - Seppo Mustonen, Aug 21 2010 with correction by Peter Kagey, Jan 24 2016
Extensions
Link corrected by Seppo Mustonen, Sep 05 2010
Definition clarified by N. J. A. Sloane, Dec 20 2012
Comments