A217294
Permutation of natural numbers arising from applying the walk of triangular horizontal-first spiral (defined in A214250) to the data of square spiral (e.g. A214526).
Original entry on oeis.org
1, 8, 2, 4, 16, 5, 6, 7, 22, 45, 23, 9, 11, 3, 15, 35, 63, 36, 17, 18, 19, 20, 21, 44, 75, 114, 76, 46, 24, 10, 28, 12, 14, 34, 62, 98, 142, 99, 64, 37, 38, 39, 40, 41, 42, 43, 74, 113, 160, 215, 161, 115, 77, 47, 25, 27, 53, 29, 13, 33, 61, 97, 141, 193, 253
Offset: 1
-
SIZE = 29 # must be 4k+1
grid = [0] * (SIZE*SIZE)
posX = posY = SIZE//2
grid[posY*SIZE+posX]=1
n = 2
def walk(stepX, stepY, chkX, chkY):
global posX, posY, n
while 1:
posX+=stepX
posY+=stepY
grid[posY*SIZE+posX]=n
n+=1
if grid[(posY+chkY)*SIZE+posX+chkX]==0:
return
while posX:
walk(0, -1, 1, 0) # up
walk(1, 0, 0, 1) # right
walk(0, 1, -1, 0) # down
walk(-1, 0, 0, -1) # left
import sys
grid2 = [0] * (SIZE*SIZE)
posX = posY = SIZE//2
grid2[posY*SIZE+posX]=1
def walk2(stepX, stepY, chkX, chkY):
global posX, posY
while 1:
a = grid[posY*SIZE+posX]
if a==0:
sys.exit(1)
print(a, end=', ')
posX+=stepX
posY+=stepY
grid2[posY*SIZE+posX]=1
if grid2[(posY+chkY)*SIZE+posX+chkX]==0:
return
while posX
A217295
Permutation of natural numbers arising from applying the walk of triangular horizontal-last spiral (defined in A214226) to the data of square spiral (e.g. A214526).
Original entry on oeis.org
1, 5, 6, 7, 22, 8, 2, 4, 16, 36, 17, 18, 19, 20, 21, 44, 75, 45, 23, 9, 11, 3, 15, 35, 63, 99, 64, 37, 38, 39, 40, 41, 42, 43, 74, 113, 160, 114, 76, 46, 24, 10, 28, 12, 14, 34, 62, 98, 142, 194, 143, 100, 65, 66, 67, 68, 69, 70, 71, 72, 73, 112, 159, 214, 277
Offset: 1
-
SIZE = 29 # must be 4k+1
grid = [0] * (SIZE*SIZE)
posX = posY = SIZE//2
grid[posY*SIZE+posX]=1
n = 2
def walk(stepX, stepY, chkX, chkY):
global posX, posY, n
while 1:
posX+=stepX
posY+=stepY
grid[posY*SIZE+posX]=n
n+=1
if grid[(posY+chkY)*SIZE+posX+chkX]==0:
return
while posX:
walk(0, -1, 1, 0) # up
walk(1, 0, 0, 1) # right
walk(0, 1, -1, 0) # down
walk(-1, 0, 0, -1) # left
import sys
grid2 = [0] * (SIZE*SIZE)
posX = posY = SIZE//2
grid2[posY*SIZE+posX]=1
def walk2(stepX, stepY, chkX, chkY):
global posX, posY
while 1:
a = grid[posY*SIZE+posX]
if a==0:
sys.exit(1)
print(a, end=', ')
posX+=stepX
posY+=stepY
grid2[posY*SIZE+posX]=1
if grid2[(posY+chkY)*SIZE+posX+chkX]==0:
return
while 1:
walk2(1, 1, -1, 0) # down-right
walk2(-1, 0, 1, -1) # left
walk2(-1, 0, 1, -1) # left
if posX<2:
break
walk2(1, -1, 1, 1) # up-right
A220102
Permutation of natural numbers arising from applying the walk of square spiral (e.g. A214526) to the data of double square spiral (defined in A220098).
Original entry on oeis.org
1, 2, 4, 6, 8, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 50, 52, 54, 56
Offset: 1
-
#include
#define SIZE 20
int grid[SIZE][SIZE];
int direction[] = {0, -1, 1, 0, 0, 1, -1, 0};
main() {
int i, j, x1, y1, x2, y2, stepSize;
int direction1pos=0, direction2pos=4, val;
x1 = y1 = x2 = y2 = SIZE/2;
for (val=grid[y1][x1]=1, stepSize=0; ; ++stepSize) {
if (x1<1 || x1>=SIZE-1 || x2<1 || x2>=SIZE-1) break;
if (y1<1 || y1>=SIZE-1 || y2<1 || y2>=SIZE-1) break;
for (i=stepSize|1; i; ++val,--i) {
x1 += direction[direction1pos ];
y1 += direction[direction1pos+1];
x2 += direction[direction2pos ];
y2 += direction[direction2pos+1];
grid[y1][x1] = val*2;
grid[y2][x2] = val*2+1;
}
direction1pos = (direction1pos+2) & 7;
direction2pos = (direction2pos+2) & 7;
}
direction1pos=0;
x1 = y1 = SIZE/2;
for (stepSize=2; ; ++stepSize) {
for (i=stepSize/2; i; --i) {
if (grid[y1][x1]==0) return;
printf("%d, ",grid[y1][x1]);
x1 += direction[direction1pos ];
y1 += direction[direction1pos+1];
}
direction1pos = (direction1pos+2) & 7;
}
}
A334742
Pascal's spiral: starting with a(1) = 1, proceed in a square spiral, computing each term as the sum of horizontally and vertically adjacent prior terms.
Original entry on oeis.org
1, 1, 1, 2, 2, 3, 3, 4, 5, 5, 6, 7, 7, 8, 10, 12, 12, 14, 17, 20, 20, 23, 27, 32, 37, 37, 42, 48, 55, 62, 62, 69, 77, 87, 99, 111, 111, 123, 137, 154, 174, 194, 194, 214, 237, 264, 296, 333, 370, 370, 407, 449, 497, 552, 614, 676, 676, 738, 807, 884, 971, 1070
Offset: 1
Spiral begins:
111--99--87--77--69--62
|
12--12--10---8---7 62
| | |
14 2---2---1 7 55
| | | | |
17 3 1---1 6 48
| | | |
20 3---4---5---5 42
| |
20--23--27--32--37--37
a(15) = 10 = 8 + 2, the sum of the cells immediately to the right and below. The term to the left is not included in the sum because it has not yet occurred in the spiral.
A220098
Manhattan distances between 2n and 1 in the double spiral with positive integers and 1 at the center.
Original entry on oeis.org
1, 2, 1, 2, 3, 2, 3, 4, 3, 2, 3, 4, 5, 4, 3, 4, 5, 6, 5, 4, 3, 4, 5, 6, 7, 6, 5, 4, 5, 6, 7, 8, 7, 6, 5, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 6, 7, 8, 9, 10, 11, 10, 9, 8, 7, 6, 7, 8, 9, 10, 11, 12, 11, 10, 9, 8, 7, 6, 7, 8, 9, 10, 11, 12, 13
Offset: 1
From _Philippe Deléham_, Mar 08 2013: (Start)
As a square array, this begins:
1, 1, 2, 2, 3, 3, 4, 4, 5, ...
2, 3, 3, 4, 4, 5, 5, 6, 6, ...
2, 4, 5, 5, 6, 6, 7, 7, 8, ...
3, 4, 6, 7, 7, 8, 8, 9, 9, ...
3, 5, 6, 8, 9, 9, 10, 10, 11, ...
4, 5, 7, 8, 10, 11, 11, 12, 12, ...
4, 6, 7, 9, 10, 12, 13, 13, 14, ...
5, 6, 8, 9, 11, 12, 14, 15, 15, ..., etc.
As a triangle, this begins:
1
2, 1
2, 3, 2
3, 4, 3, 2
3, 4, 5, 4, 3
4, 5, 6, 5, 4, 3, etc. (End)
-
#include
#define SIZE 20
int grid[SIZE][SIZE];
int direction[] = {0, -1, 1, 0, 0, 1, -1, 0};
main() {
int i, j, x1, y1, x2, y2, stepSize;
int direction1pos=0, direction2pos=4, val;
x1 = y1 = x2 = y2 = SIZE/2;
for (val=grid[y1][x1]=1, stepSize=0; ; ++stepSize) {
if (x1<1 || x1>=SIZE-1 || x2<1 || x2>=SIZE-1) break;
if (y1<1 || y1>=SIZE-1 || y2<1 || y2>=SIZE-1) break;
for (i=stepSize|1; i; ++val,--i) {
x1 += direction[direction1pos ];
y1 += direction[direction1pos+1];
x2 += direction[direction2pos ];
y2 += direction[direction2pos+1];
grid[y1][x1] = val*2;
grid[y2][x2] = val*2+1;
printf("%d, ",abs(x1-SIZE/2)+abs(y1-SIZE/2));
}
direction1pos = (direction1pos+2) & 7;
direction2pos = (direction2pos+2) & 7;
}
for (i=0; i
-
step(v, m) = concat(v, vector(m, k, 1+v[#v-k+1]))
a(max_n) = {my(v=[0], k=1); while(#v < max_n+1, v=step(v,k); k++); v[2..max_n+1]} \\ Thomas Scheuerle, Jan 07 2025
-
A053615(n) = if(n<1, 0, sqrtint(n) - A053615(n - sqrtint(n)))
a(n) = A053615(floor( floor( (sqrtint(n*8) + 1)/2 )^2/2 ) + n) \\ Thomas Scheuerle, Jan 07 2025
A232113
a(n) is the Manhattan distance between n and 2*n in a square spiral of positive integers with 1 at the center.
Original entry on oeis.org
1, 2, 3, 2, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 3, 4, 3, 2, 3, 2, 1, 2, 1, 2, 3, 2, 3, 4, 3, 4, 5, 6, 5, 6, 7, 8, 7, 8, 9, 10, 11, 8, 11, 12, 13, 12, 9, 10, 13, 16, 15, 12, 9, 12, 15, 16, 15, 12, 9, 12, 15, 14, 13, 12, 11, 12, 13, 12, 11, 10, 9, 10, 11, 10, 9, 8, 7, 8, 9
Offset: 1
A232114
a(n) is the Manhattan distance between n and n^2 in a square spiral of positive integers with 1 at the center.
Original entry on oeis.org
0, 2, 2, 2, 6, 4, 6, 8, 6, 12, 8, 12, 12, 12, 16, 12, 20, 14, 20, 18, 20, 22, 20, 26, 20, 30, 22, 30, 26, 30, 30, 30, 34, 30, 38, 30, 42, 32, 42, 36, 42, 40, 42, 44, 42, 48, 42, 52, 42, 56, 44, 56, 48, 56, 52, 56, 56, 56, 60, 56, 64, 56, 68, 56, 72, 58, 72, 62, 72, 66
Offset: 1
A366353
a(0) = 0; for n > 0, a(n) is the largest taxicab distance on a square spiral between a(n-1) and any previous occurrence of a(n-1). If a(n-1) has not previously occurred then a(n) = 0.
Original entry on oeis.org
0, 0, 1, 0, 2, 0, 2, 2, 3, 0, 4, 0, 4, 2, 5, 0, 6, 0, 6, 2, 6, 4, 7, 0, 6, 8, 0, 7, 5, 4, 8, 5, 3, 4, 6, 8, 10, 0, 9, 0, 7, 7, 8, 12, 0, 7, 6, 8, 10, 12, 6, 10, 11, 0, 9, 8, 13, 0, 11, 6, 9, 6, 11, 10, 13, 8, 12, 13, 11, 10, 9, 12, 8, 15, 0, 13, 13, 12, 11, 12, 13, 16, 0, 13, 15, 11, 11, 10, 12
Offset: 0
The spiral begins:
.
.
10--8---6---4---3---5---8 :
| | :
0 6---0---5---2---4 4 9
| | | | |
9 0 2---0---1 0 5 0
| | | | | | |
0 6 0 0---0 4 7 11
| | | | | |
7 2 2---2---3---0 0 10
| | | |
7 6---4---7---0---6---8 6
| |
8---12--0---7---6---8---10--12
.
a(2) = 1 as the taxicab distance between a(1) = 0, at (1,0) relative to the starting square, and the only previous occurrence of 0, a(0) at (0,0), is 1.
a(8) = 3 as the maximum taxicab distance between a(7) = 2, at (0,-1) relative to the starting square, and any previous occurrence of 2 is 3, to a(4) = 2 at (-1,1) relative to the starting square.
a(32) = 3 as the maximum taxicab distance between a(31) = 5, at (2,3) relative to the starting square, and any previous occurrence of 5 is 3, to a(28) = 5 at (3,1) relative to the starting square, and also to a(14) = 5 at (0,2) relative to the starting square. This is the first term to differ from A366354.
A366354
a(0) = 0; for n > 0, a(n) is the largest taxicab distance on a square spiral between any two previous occurrences of a(n-1). If a(n-1) has not previously occurred then a(n) = 0.
Original entry on oeis.org
0, 0, 1, 0, 2, 0, 2, 2, 3, 0, 4, 0, 4, 2, 5, 0, 6, 0, 6, 2, 6, 4, 7, 0, 6, 8, 0, 7, 5, 4, 8, 5, 4, 8, 8, 9, 0, 10, 0, 10, 2, 7, 8, 12, 0, 10, 8, 12, 4, 8, 12, 7, 8, 12, 10, 9, 6, 12, 12, 12, 12, 12, 12, 12, 13, 0, 11, 0, 11, 2, 8, 12, 14, 0, 11, 8, 12, 14, 5, 8, 12, 15, 0, 15, 2, 9, 10, 9, 10, 11
Offset: 0
The spiral begins:
.
.
0---9---8---8---4---5---8 :
| | :
10 6---0---5---2---4 4 10
| | | | |
0 0 2---0---1 0 5 12
| | | | | | |
10 6 0 0---0 4 7 8
| | | | | |
2 2 2---2---3---0 0 7
| | | |
7 6---4---7---0---6---8 12
| |
8--12---0--10---8--12---4---8
.
a(2) = 1 as the maximum taxicab distance between 0 = a(1) and the only previous occurrence of 0, a(0) at (0,0), is 1.
a(8) = 3 as the maximum taxicab distance between any two previous occurrences of 2 = a(7) is 3, between a(3) = 2, at (-1,1) relative to the starting square, and a(7) = 2 at (0,-1) relative to the starting square.
a(32) = 4 as the maximum taxicab distance between any two previous occurrences of 5 = a(31) is 4, between a(14) = 5, at (0,2) relative to the starting square, and a(28) = 5 at (3,1) relative to the starting square. This is the first term to differ from A366353.
A232115
a(n) is the Manhattan distance between n and n(n+1)/2 in a square spiral of positive integers with 1 at the center.
Original entry on oeis.org
0, 1, 3, 4, 2, 3, 5, 6, 4, 5, 9, 6, 6, 7, 11, 8, 8, 15, 9, 10, 10, 13, 11, 12, 22, 11, 15, 18, 12, 15, 17, 22, 12, 21, 25, 10, 26, 21, 19, 18, 24, 27, 15, 34, 24, 21, 31, 20, 28, 21, 31, 24, 28, 41, 19, 36, 36, 23, 35, 26, 38, 23, 41, 36, 28, 53, 29, 38, 40, 31, 39
Offset: 1
-
import math
def get_x_y(n):
sr = math.isqrt(n-1)
sr = sr-1+(sr&1)
rm = n-sr*sr
d = (sr+1)//2
if rm<=sr+1:
return -d+rm,d
if rm<=sr*2+2:
return d,d-(rm-(sr+1))
if rm<=sr*3+3:
return d-(rm-(sr*2+2)),-d
return -d,-d+rm-(sr*3+3)
for n in range(1,333):
x0,y0 = get_x_y(n)
x1,y1 = get_x_y(n*(n+1)//2)
print(abs(x1-x0)+abs(y1-y0), end=', ')
Comments