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.

A214251 Sum of the eight nearest neighbors of n in a right triangular type-2 spiral with positive integers.

This page as a plain text file.
%I A214251 #17 Jun 04 2025 12:21:05
%S A214251 62,64,69,125,94,111,170,118,105,116,169,132,131,151,192,284,217,201,
%T A214251 206,220,258,353,265,234,227,235,243,269,349,285,275,283,291,299,328,
%U A214251 387,515,412,378,374,382,390,398,421,477,608,484,435,419,427,435
%N A214251 Sum of the eight nearest neighbors of n in a right triangular type-2 spiral with positive integers.
%C A214251 Right triangular type-1 spiral (A214230): implements the sequence Up, Right-down, Left.
%C A214251 Right triangular type-2 spiral: Left, Up, Right-down.
%C A214251 Right triangular type-3 spiral (A214252): Right-down, Left, Up.
%e A214251 Right triangular type-2 spiral begins:
%e A214251 67
%e A214251 66  68
%e A214251 65  37  69
%e A214251 64  36  38  70
%e A214251 63  35  16  39  71
%e A214251 62  34  15  17  40  72
%e A214251 61  33  14   4  18  41  73
%e A214251 60  32  13   3   5  19  42  74
%e A214251 59  31  12   2   1   6  20  43  75
%e A214251 58  30  11  10   9   8   7  21  44  76
%e A214251 57  29  28  27  26  25  24  23  22  45  77
%e A214251 56  55  54  53  52  51  50  49  48  47  46  78
%e A214251 The eight nearest neighbors of 5 are 1, 2, 3, 4, 18, 41, 19, 6. Their sum is a(5)=94.
%o A214251 (Python)
%o A214251 SIZE=29  # must be odd
%o A214251 grid = [0] * (SIZE*SIZE)
%o A214251 saveX = [0]* (SIZE*SIZE)
%o A214251 saveY = [0]* (SIZE*SIZE)
%o A214251 saveX[1] = saveY[1] = posX = posY = SIZE//2
%o A214251 grid[posY*SIZE+posX]=1
%o A214251 n = 2
%o A214251 def walk(stepX, stepY, chkX, chkY):
%o A214251   global posX, posY, n
%o A214251   while 1:
%o A214251     posX+=stepX
%o A214251     posY+=stepY
%o A214251     grid[posY*SIZE+posX]=n
%o A214251     saveX[n]=posX
%o A214251     saveY[n]=posY
%o A214251     n+=1
%o A214251     if posY==0 or grid[(posY+chkY)*SIZE+posX+chkX]==0:
%o A214251         return
%o A214251 while 1:
%o A214251     walk(-1, 0,  0, -1)    # left
%o A214251     walk(0, -1,  1,  1)    # up
%o A214251     if posY==0:
%o A214251         break
%o A214251     walk( 1, 1, -1,  0)    # right-down
%o A214251 for n in range(1, 92):
%o A214251     posX = saveX[n]
%o A214251     posY = saveY[n]
%o A214251     k = grid[(posY-1)*SIZE+posX] + grid[(posY+1)*SIZE+posX]
%o A214251     k+= grid[(posY-1)*SIZE+posX-1] + grid[(posY-1)*SIZE+posX+1]
%o A214251     k+= grid[(posY+1)*SIZE+posX-1] + grid[(posY+1)*SIZE+posX+1]
%o A214251     k+= grid[posY*SIZE+posX-1] + grid[posY*SIZE+posX+1]
%o A214251     print(k, end=', ')
%Y A214251 Cf. A214230.
%Y A214251 Cf. A214252.
%K A214251 nonn,easy
%O A214251 1,1
%A A214251 _Alex Ratushnyak_, Jul 08 2012