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.

A217015 Permutation of natural numbers arising from applying the walk of a square spiral (e.g. A214526) to the data of rotated-square spiral (defined in A215468).

Original entry on oeis.org

1, 5, 6, 2, 8, 3, 10, 4, 12, 24, 13, 14, 27, 15, 7, 17, 31, 18, 9, 20, 35, 21, 11, 23, 39, 59, 40, 25, 26, 43, 64, 44, 28, 16, 30, 48, 70, 49, 32, 19, 34, 53, 76, 54, 36, 22, 38, 58, 82, 110, 83, 60, 41, 42, 63, 88, 117, 89, 65, 45, 29, 47, 69, 95, 125, 96, 71, 50
Offset: 1

Views

Author

Alex Ratushnyak, Sep 23 2012

Keywords

Crossrefs

Programs

  • Python
    SIZE = 33       # must be 4k+1
    grid = [0] * (SIZE*SIZE)
    posX = posY = SIZE//2
    grid[posY*SIZE+posX]=1
    posX += 1
    grid[posY*SIZE+posX]=2
    n = 3
    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!=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
    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(0, -1, 1, 0)    # up
        walk2(1, 0, 0, 1)     # right
        walk2(0, 1, -1, 0)    # down
        walk2(-1, 0, 0, -1)   # left