cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A274923 List of y-coordinates of point moving in counterclockwise square spiral.

This page as a plain text file.
%I A274923 #57 Aug 06 2025 16:53:25
%S A274923 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,
%T A274923 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,
%U A274923 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
%N A274923 List of y-coordinates of point moving in counterclockwise square spiral.
%C A274923 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
%C A274923 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
%D A274923 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.
%H A274923 Alois P. Heinz, <a href="/A274923/b274923.txt">Table of n, a(n) for n = 1..10000</a>
%H A274923 <a href="/plot2a?name1=A174344&amp;name2=A274923&amp;tform1=untransformed&amp;tform2=untransformed&amp;shift=0&amp;radiop1=xy&amp;drawlines=true">Visualization of spiral using Plot 2.</a> - _Hugo Pfoertner_, May 29 2018
%H A274923 <a href="/index/Con#coordinates_2D_curves">Index entries for sequences related to coordinates of 2D curves</a>
%p A274923 fy:=proc(n) option remember; local k; if n=1 then 0 else
%p A274923 k:=floor(sqrt(4*(n-2)+1)) mod 4;
%p A274923 fy(n-1) - cos(k*Pi/2); fi; end;
%p A274923 [seq(fy(n),n=1..120)]; # Based on _Seppo Mustonen_'s formula in A174344.
%t A274923 a[n_] := a[n] = If[n == 0, 0, a[n-1] - Cos[Mod[Floor[Sqrt[4*(n-1)+1]], 4]* Pi/2]];
%t A274923 Table[a[n], {n, 0, 100}] (* _Jean-François Alcover_, Jun 11 2018, after _Seppo Mustonen_ *)
%o A274923 (PARI) L=1;d=1;
%o A274923 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
%o A274923 (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
%o A274923 (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
%o A274923 (Python) # Based on Kevin Ryde's PARI script
%o A274923 import math
%o A274923 def A274923(n):
%o A274923     n -= 1
%o A274923     m = math.isqrt(n)
%o A274923     k = math.ceil(m/2)
%o A274923     n -= 4*k*k
%o A274923     if n < 0: return 3*k+n if n < -m else k
%o A274923     return k-n if n < m else -k # _David Radcliffe_, Aug 04 2025
%Y A274923 Cf. A268038 (negated), A317186 (indices of 0's).
%Y A274923 Cf. A174344 (x-coordinates).
%Y A274923 The (x,y) coordinates for a point sweeping a quadrant by antidiagonals are (A025581, A002262). - _N. J. A. Sloane_, Jul 17 2018
%Y A274923 A296030 gives pairs (x = A174344(n), y = a(n)). - _M. F. Hasler_, Oct 20 2019
%Y A274923 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
%K A274923 sign,easy
%O A274923 1,13
%A A274923 _N. J. A. Sloane_, Jul 11 2016