A220098 Manhattan distances between 2n and 1 in the double spiral with positive integers and 1 at the center.
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
Examples
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)
Programs
-
C
#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 -
PARI
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
-
PARI
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
Formula
abs( a(n) - a(n-1) ) = 1.
From Thomas Scheuerle, Jan 07 2025: (Start)
a(n*(n+1)/2 - k) = 1 + a(n*(n-1)/2 + k) with a(0) = 0 and for 0 <= k < n.
Comments