A174344
List of x-coordinates of point moving in clockwise square spiral.
Original entry on oeis.org
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
Nikolas Garofil (nikolas(AT)garofil.be), Mar 16 2010
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
- 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.
- 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
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
-
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
-
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
-
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 *)
-
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
-
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(nKevin Ryde, Sep 16 2019
-
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
-
# 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
A274923
List of y-coordinates of point moving in counterclockwise square spiral.
Original entry on oeis.org
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
Offset: 1
- 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.
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
-
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.
-
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 *)
-
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
-
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(nKevin Ryde, Sep 17 2019
-
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
-
# Based on Kevin Ryde's PARI script
import math
def A274923(n):
n -= 1
m = math.isqrt(n)
k = math.ceil(m/2)
n -= 4*k*k
if n < 0: return 3*k+n if n < -m else k
return k-n if n < m else -k # David Radcliffe, Aug 04 2025
A296030
Pairs of coordinates for successive integers in the square spiral (counterclockwise).
Original entry on oeis.org
0, 0, 1, 0, 1, 1, 0, 1, -1, 1, -1, 0, -1, -1, 0, -1, 1, -1, 2, -1, 2, 0, 2, 1, 2, 2, 1, 2, 0, 2, -1, 2, -2, 2, -2, 1, -2, 0, -2, -1, -2, -2, -1, -2, 0, -2, 1, -2, 2, -2, 3, -2, 3, -1, 3, 0, 3, 1, 3, 2, 3, 3, 2, 3, 1, 3, 0, 3, -1, 3, -2, 3, -3, 3, -3, 2
Offset: 1
The integer 1 occupies the initial position, so its coordinates are {0,0}; therefore a(1)=0 and a(2)=0.
The integer 2 occupies the position immediately to the right of 1, so its coordinates are {1,0}.
The integer 3 occupies the position immediately above 2, so its coordinates are {1,1}; etc.
- S. Wolfram, A New Kind of Science, Wolfram Media, 2002; p. 935.
Cf. Diagonal rays (+-n,+-n):
A002939 (2n(2n-1): 0, 2, 12, 30, ...: NE),
A016742 (4n^2: 0, 4, 16, 36, ...: NW),
A002943 (2n(2n+1): 0, 6, 20, 42, ...: SW) and
A033996 (4n(n+1): 0, 8, 24, 48, ...: SE).
-
f[n_] := Block[{k = Ceiling[(Sqrt[n] - 1)/2], m, t}, t = 2k +1; m = t^2; t--; If[n >= m - t, {k -(m - n), -k}, m -= t; If[n >= m - t, {-k, -k +(m - n)}, m -= t; If[n >= m - t, {-k +(m - n), k}, {k, k -(m - n - t)}]]]]; Array[f, 40] // Flatten (* Robert G. Wilson v, Dec 04 2017 *)
f[n_] := Block[{k = Mod[ Floor[ Sqrt[4 If[OddQ@ n, (n + 1)/2 - 2, (n/2 - 2)] + 1]], 4]}, f[n - 2] + If[OddQ@ n, Sin[k*Pi/2], -Cos[k*Pi/2]]]; f[1] = f[2] = 0; Array[f, 90] (* Robert G. Wilson v, Dec 14 2017 *)
f[n_] := With[{t = Round@ Sqrt@ n}, 1/2*(-1)^t*({1, -1}(Abs[t^2 - n] - t) + t^2 - n - Mod[t, 2])]; Table[f@ n, {n, 0, 95}] // Flatten (* Mikk Heidemaa May 23 2020, after Stephen Wolfram *)
-
apply( {coords(n)=my(m=sqrtint(n), k=m\/2); if(m <= n -= 4*k^2, [n-3*k,-k], n >= 0, [-k,k-n], n >= -m, [-k-n,k], [k,3*k+n])}, [0..99]) \\ Use concat(%) to remove brackets '[', ']'. This function gives the coordinates of n on the spiral starting with 0 at (0,0), as shown in Examples for A174344, A274923, ..., so (a(2n-1),a(2n)) = coords(n-1). To start with 1 at (0,0), change n to n-=1 in sqrtint(). The inverse function is pos(x,y) given e.g. in A316328. - M. F. Hasler, Oct 20 2019
-
from math import ceil, sqrt
def get_coordinate(n):
k=ceil((sqrt(n)-1)/2)
t=2*k+1
m=t**2
t=t-1
if n >= m - t:
return k - (m-n), -k
else:
m -= t
if n >= m - t:
return -k, -k+(m-n)
else:
m -= t
if n >= m-t:
return -k+(m-n), k
else:
return k, k-(m-n-t)
A343640
Coordinate triples (x(n), y(n), z(n); n >= 0) of the 3D square spiral filling space with shells of increasing radius for the sup-norm, in turn filled by squares extending from one pole to the opposite one.
Original entry on oeis.org
0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, -1, 1, 1, -1, 0, 1, -1, -1, 1, 0, -1, 1, 1, -1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0, -1, 1, 0, -1, 0, 0, -1, -1, 0, 0, -1, 0, 1, -1, 0, 1, 0, -1, 1, 1, -1, 0, 1, -1, -1, 1, -1, -1, 0, -1, -1, -1, -1, 0, -1, -1, 1, -1, -1, 0, 0, -1, 0, 0, -2, 1, 0, -2, 1, 1, -2, 0, 1, -2, -1, 1, -2, -1, 0, -2, -1, -1, -2, 0, -1, -2, 1, -1, -2
Offset: 0
Shell r = 0 is the origin, {(0,0,0)}.
Shell r = 1 contains the 3*3 + 4*2 + 3*3 = 26 points with oo-norm 1, i.e., all points with coordinates within {-1, 0, 1} except for the origin. They are listed in a square spiral starting at the North Pole: (0,0,1), (1,0,1), (1,1,1), (0,1,1), (-1,1,1), (-1,0,1), (-1,-1,1), (0,-1,1), (1,-1,1); then on the equator: (1,0,0), (1,1,0), (0,1,0), (-1,1,0), (-1,0,0), (-1,-1,0), (0,-1,0), (1,-1,0), and then on the South face using an inward spiral: (1,0,-1), (1,1,-1), (0,1,-1), (-1,1,-1), (-1,0,-1), (-1,-1,-1), (0,-1,-1), (1,-1,-1), (0,0,-1).
Since there are no empty shells, the z-coordinate is always increasing for even r and decreasing for odd r.
-
A343640_row(n)={local(L=List(), a(r, z, d=I)= if(r, for(i=1,8*r, listput(L,[real(r),imag(r),z]); r+=d; abs(real(r))==abs(imag(r)) && d*=I), listput(L,[0,0,z])), s=(-1)^n /* flip South <-> North for odd n */); /* main prog: (1) square spiral on South face from center to board */ for(d=!n,n, a(d,-s*n)); /* (2) "equatorial(?) bands" from South to North */ for(z=1-n,n-1, a(n,s*z)); /* (3) square spiral on North face ending in pole */ for(d=0,n, a(n-d,s*n)); Vec(L)} \\ row n of the table = list of points (x,y,z) in the shell n, i.e., with sup norm n. [Missing "s*" in a(n,s*z) added on May 27 2021]
A343640_vec=concat([A343640_row(r) | r<-[0..2]]) \\ From r=0 up to n there are (2n+1)^3 points with 3 coordinates each!
A336336
Squared distance from start of a point moving in a square spiral.
Original entry on oeis.org
0, 1, 2, 1, 2, 1, 2, 1, 2, 5, 4, 5, 8, 5, 4, 5, 8, 5, 4, 5, 8, 5, 4, 5, 8, 13, 10, 9, 10, 13, 18, 13, 10, 9, 10, 13, 18, 13, 10, 9, 10, 13, 18, 13, 10, 9, 10, 13, 18, 25, 20, 17, 16, 17, 20, 25, 32, 25, 20, 17, 16, 17, 20, 25, 32, 25, 20, 17, 16, 17, 20, 25, 32
Offset: 1
-
A336336(m)={my(v=vectorsmall(m));for(Lstart=0,1,my(L=Lstart,d=1,n=0);for(r=1,oo,d=-d;my(k=floor(r/2)*d); for(j=1,L++,n++;if(n<=m,v[n]+=k*k));forstep(j=k-d,-floor((r+1)/2)*d+d,-d,n++;if(n<=m,v[n]+=j*j));if(n>m,break)));v};
A336336(73)
A334751
a(n) is the number immediately above n in a clockwise square spiral of the positive integers with the first step to the right.
Original entry on oeis.org
8, 9, 2, 1, 6, 7, 22, 23, 24, 25, 10, 11, 12, 3, 4, 5, 18, 19, 20, 21, 44, 45, 46, 47, 48, 49, 26, 27, 28, 29, 30, 13, 14, 15, 16, 17, 38, 39, 40, 41, 42, 43, 74, 75, 76, 77, 78, 79, 80, 81, 50, 51, 52, 53, 54, 55, 56, 31, 32, 33, 34, 35, 36, 37, 66, 67, 68, 69
Offset: 1
For n = 1, a(1) = 8 because 8 is immediately above one in the clockwise square spiral with first step to the right:
21--22--23--24--25--26
| |
20 7---8---9---10 27
| | | |
19 6 1---2 11 28
| | | | |
18 5---4---3 12 29
| | |
17--16--15--14--13 30
|
36--35--34--33--32--31
A334752
a(n) is the number immediately below n in a clockwise square spiral of the positive integers with the first step to the right.
Original entry on oeis.org
4, 3, 14, 15, 16, 5, 6, 1, 2, 11, 12, 13, 32, 33, 34, 35, 36, 17, 18, 19, 20, 7, 8, 9, 10, 27, 28, 29, 30, 31, 58, 59, 60, 61, 62, 63, 64, 37, 38, 39, 40, 41, 42, 21, 22, 23, 24, 25, 26, 51, 52, 53, 54, 55, 56, 57, 92, 93, 94, 95, 96, 97, 98, 99, 100, 65, 66
Offset: 1
For n = 1, a(1) = 4 because 4 is immediately below 1 in the clockwise square spiral with first step to the right:
21--22--23--24--25--26
| |
20 7---8---9---10 27
| | | |
19 6 1---2 11 28
| | | | |
18 5---4---3 12 29
| | |
17--16--15--14--13 30
|
36--35--34--33--32--31
A329972
Y-coordinate of a point moving in a triangular spiral.
Original entry on oeis.org
0, 0, 1, 0, -1, -1, -1, -1, -1, -1, 0, 1, 2, 1, 0, -1, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -1, 0, 1, 2, 3, 2, 1, 0, -1, -2, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -2, -1, 0, 1, 2, 3, 4, 3, 2, 1, 0, -1, -2, -3, -4
Offset: 0
y
|
4 | 56
| \
| \
| \
3 | 30 55
| / \ \
| / \ \
| / \ \
2 | 31 12 29 54
| / / \ \ \
| / / \ \ \
| / / \ \ \
1 | 32 13 2 11 28 53
| / / / \ \ \ \
| / / / \ \ \ \
| / / / \ \ \ \
0 | 33 14 3 0---1 10 27 52
| / / / \ \ \
| / / / \ \ \
| / / / \ \ \
-1 | 34 15 4---5---6---7---8---9 26 51
| / / \ \
| / / \ \
| / / \ \
-2 | 35 16--17--18--19--20--21--22--23--24--25 50
| / \
| / \
| / \
-3 | 36--37--38--39--40--41--42--43--44--45--46--47--48--49
|
+--------------------------------------------------------
x: -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7
-
a[n_] := Table[Floor[Min[#*Max[0, 2*Mod[#, 2] - 2], -2*#*Mod[#, -1]] + Ceiling[-#/2]] &[Sqrt@ k], {k, 0, n}]; a[64]
A332582
Label the cells of the infinite 2D square lattice with the square spiral (or Ulam spiral), starting with 1 at the center; sequence lists primes that are visible from square 1.
Original entry on oeis.org
2, 3, 5, 7, 29, 41, 47, 83, 89, 97, 103, 107, 109, 113, 173, 179, 181, 191, 193, 199, 223, 293, 311, 317, 347, 353, 359, 443, 449, 457, 461, 467, 479, 487, 491, 499, 503, 509, 521, 523, 631, 641, 643, 647, 653, 659, 661, 673, 683, 691, 701, 709, 719, 727, 857, 863, 887, 929, 947, 953, 1091
Offset: 1
The 2D grid is shown below. Composite numbers are shown as a '*'. The primes that are blocked from the central 1 square are in parentheses; these all have another composite or prime number directly between their position and the central square.
.
.
*----*----*--(61)---*--(59)---*----*
|
(37)---*----*----*----*----*--(31) *
| | |
* (17)---*----*----*--(13) * *
| | | | |
* * 5----*----3 * 29 *
| | | | | | |
* (19) * 1----2 (11) * (53)
| | | | | |
41 * 7----*----*----* * *
| | | |
* *----*--(23)---*----*----* *
| |
(43)---*----*----*---47----*----*----*
.
.
a(1) = 2 to a(4) = 7 are all primes adjacent to the central 1 point, thus all are visible from that square.
a(5) = 29 as primes 11, 13, 17, 19, 23 are blocked from the central 1 point by points numbered 2, 3, 5, 6, 8 respectively.
-
x:= 0: y:= 0: R:= NULL: count:= 0:
for i from 2 while count < 100 do
if x >= y then
if x < -y + 1 then x:= x+1
elif x > y then y:= y+1
else x:= x-1
fi
elif x <= -y then y:= y-1
else x:= x-1
fi;
if isprime(i) and igcd(abs(x),abs(y))=1 then R:= R,i; count:= count+1 fi
od:
R; # Robert Israel, Feb 16 2024
A335298
a(n) is the squared distance between the points P(n) and P(0) on a plane, n >= 0, such that the distance between P(n) and P(n+1) is n+1 and, going from P(n) to P(n+2), a 90-degree left turn is taken in P(n+1).
Original entry on oeis.org
0, 1, 5, 8, 8, 13, 25, 32, 32, 41, 61, 72, 72, 85, 113, 128, 128, 145, 181, 200, 200, 221, 265, 288, 288, 313, 365, 392, 392, 421, 481, 512, 512, 545, 613, 648, 648, 685, 761, 800, 800, 841, 925, 968, 968, 1013, 1105, 1152, 1152, 1201, 1301, 1352, 1352, 1405, 1513
Offset: 0
n n*i^(n-1) z(n) a(n)
------------------------------------
0 0 0 0
1 1 1 1
2 2i 1+2i 5 = 1^2 + 2^2
3 -3 -2+2i 8 = 2^2 + 2^2
4 -4i -2-2i 8
5 5 3-2i 13 = 3^2 + 2^2
6 6i 3+4i 25 = 3^2 + 4^2
-
z[0]=0; z[n_]:=z[n-1]+n*I^(n-1); a[n_]:=z[n]*Conjugate[z[n]]; Array[a,55,0] (* Stefano Spezia, Jun 28 2020 *)
Showing 1-10 of 14 results.
Comments