|
|
A174344
|
|
List of x-coordinates of point moving in clockwise square spiral.
|
|
77
|
|
|
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
|
|
|
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
|
|
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
.
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
|
|
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;
|
|
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
|
|
CROSSREFS
|
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
|
|
KEYWORD
|
sign
|
|
AUTHOR
|
Nikolas Garofil (nikolas(AT)garofil.be), Mar 16 2010
|
|
EXTENSIONS
|
|
|
STATUS
|
approved
|
|
|
|