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.

Showing 1-1 of 1 results.

A215471 Numbers k such that in a rotated-square spiral with positive integers (A215468) among k's eight nearest neighbors five or more are primes.

Original entry on oeis.org

8, 30, 138, 658, 2620, 3010, 3168, 3372, 3462, 8628, 11940, 17682, 24918, 27918, 32560, 39228, 39790, 40128, 43608, 48532, 53268, 55372, 56040, 56712, 73362, 85200, 85888, 90646, 96052, 101748, 102652, 104382, 112068, 113932, 115330, 119298, 128518, 129288, 131500
Offset: 1

Views

Author

Alex Ratushnyak, Aug 11 2012

Keywords

Examples

			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
Among eight nearest neighbors of 30 five are primes: 7, 17, 31, 29, 47.
		

Crossrefs

Programs

  • Python
    SIZE = 3335  # must be odd
    TOP = SIZE*SIZE
    t = TOP//2
    prime = [1]*t
    prime[1]=0
    for i in range(4,t,2):
        prime[i]=0
    for i in range(3,t,2):
        if prime[i]==1:
            for j in range(i*3,t,i*2):
                prime[j]=0
    grid = [0] * TOP
    posX = posY = SIZE//2
    saveX = [0]* (t+1)
    saveY = [0]* (t+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]
        a,b=(grid[(posY-1)*SIZE+posX-1]) , (grid[(posY-1)*SIZE+posX+1])
        c,d=(grid[(posY+1)*SIZE+posX-1]) , (grid[(posY+1)*SIZE+posX+1])
        e,f=(grid[(posY-1)*SIZE+posX  ]) , (grid[(posY+1)*SIZE+posX  ])
        g,h=(grid[ posY   *SIZE+posX-1]) , (grid[ posY   *SIZE+posX+1])
        if a*b==0 or c*d==0 or e*f==0 or g*h==0:
            break
        z = prime[a]+prime[b]+prime[c]+prime[d]
        if z+prime[e]+prime[f]+prime[g]+prime[h] >= 5:
            print(s, end=' ')
    
  • Python
    # See A215468 for the definition of spiral().
    from sympy import isprime
    def neighbors(n):
        x = A010751(n-1)
        y = A305258(n-1)
        return [spiral(x+i, y+j) for i in (-1, 0, 1) for j in (-1, 0, 1) if (i, j) != (0, 0)]
    def is_A215471(n): return sum(map(isprime, neighbors(n))) >= 5 # David Radcliffe, Aug 05 2025
Showing 1-1 of 1 results.