login
The OEIS Foundation is supported by donations from users of the OEIS and by a grant from the Simons Foundation.

 

Logo

Thanks to everyone who made a donation during our annual appeal!
To see the list of donors, or make a donation, see the OEIS Foundation home page.

Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A215468 Sum of the 8 nearest neighbors of n in a rotated-square spiral with positive integers. 5
50, 62, 72, 86, 76, 84, 122, 88, 144, 104, 166, 120, 152, 160, 144, 218, 160, 168, 248, 184, 192, 278, 208, 216, 260, 268, 240, 248, 346, 264, 272, 280, 384, 296, 304, 312, 422, 328, 336, 344, 400, 408, 368, 376, 384, 506, 400, 408, 416, 424, 552, 440, 448, 456, 464, 598 (list; graph; refs; listen; history; text; internal format)
OFFSET

1,1

LINKS

Table of n, a(n) for n=1..56.

EXAMPLE

Spiral begins:

                            113

                        112  85  86

                    111  84  61  62  87

                110  83  60  41  42  63  88

            109  82  59  40  25  26  43  64  89

        108  81  58  39  24  13  14  27  44  65  90

    107  80  57  38  23  12   5   6  15  28  45  66  91

106  79  56  37  22  11   4   1   2   7  16  29  46  67  92

    105  78  55  36  21  10   3   8  17  30  47  68  93

        104  77  54  35  20   9  18  31  48  69  94

            103  76  53  34  19  32  49  70  95

                102  75  52  33  50  71  96

                    101  74  51  72  97

                        100  73  98

                             99

The 8 nearest neighbors of 4 are 1,3,5,10,11,12,21,23, their sum is 86, so a(4)=86.

PROG

(Python)

SIZE=17  # must be odd

grid = [0] * (SIZE*SIZE)

posX = posY = SIZE//2

saveX = [0]* (SIZE*SIZE+1)

saveY = [0]* (SIZE*SIZE+1)

grid[posY*SIZE+posX]=1

saveX[1]=posX

saveY[1]=posY

posX += 1

grid[posY*SIZE+posX]=2

saveX[2]=posX

saveY[2]=posY

n = 3

def walk(stepX, stepY, chkX, chkY):

  global posX, posY, n

  while 1:

    posX+=stepX

    posY+=stepY

    grid[posY*SIZE+posX]=n

    saveX[n]=posX

    saveY[n]=posY

    n+=1

    if grid[(posY+chkY)*SIZE+posX+chkX]==0:

        return

while posX!=SIZE-1:

    walk(-1,  1, -1, -1)    # down-left

    walk(-1, -1,  1, -1)    # up-left

    walk( 1, -1,  1,  0)    # up-right

    walk( 1,  0,  1,  1)    # right

    walk( 1,  1, -1,  1)    # down-right

for s in range(1, n):

    posX = saveX[s]

    posY = saveY[s]

    i, j = grid[(posY-1)*SIZE+posX-1], grid[(posY-1)*SIZE+posX+1]

    u, v = grid[(posY+1)*SIZE+posX-1], grid[(posY+1)*SIZE+posX+1]

    if i==0 or j==0 or u==0 or v==0:

        break

    k = grid[(posY-1)*SIZE+posX  ] + grid[(posY+1)*SIZE+posX  ]

    k+= grid[ posY   *SIZE+posX-1] + grid[ posY   *SIZE+posX+1]

    print i+j+u+v+k,

print

for y in range(SIZE):

    for x in range(SIZE):

        print '%3d' % grid[y*SIZE+x],

    print

CROSSREFS

Coordinates (but 0-based): A010751, A305258.

Other spiral sums: A214176, A214177, A214226, A214227, A214230, A214231, A214250, A214251, A214252.

Sequence in context: A062118 A167329 A179796 * A109552 A206263 A007692

Adjacent sequences:  A215465 A215466 A215467 * A215469 A215470 A215471

KEYWORD

nonn,easy

AUTHOR

Alex Ratushnyak, Aug 11 2012

STATUS

approved

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recent
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified January 17 23:09 EST 2021. Contains 340249 sequences. (Running on oeis4.)