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-2 of 2 results.

A309701 Primes with record Manhattan distance from origin. When starting rightwards in a grid, turn left after a prime number. If not, walk straight on.

Original entry on oeis.org

2, 3, 11, 29, 59, 97, 151, 193, 211, 223, 239, 281, 307, 311, 331, 337, 479, 541, 593, 613, 631, 641, 659, 877, 881, 907, 911, 997, 1409, 1861, 1907, 2267, 2281, 2287, 2309, 2311, 2503, 2579, 2609, 2617, 2657, 2671, 2677, 3671, 3691, 3697, 3727, 3761, 3767, 3793, 3797, 4201, 4327, 4357, 4391, 4397, 4507, 4721, 4751, 4909
Offset: 1

Views

Author

Pieter Post, Aug 13 2019

Keywords

Comments

This sequence differs from A309755 where the Euclidean distance is used.

Examples

			Grid of the first 34 steps. 0 represents (0,0).
xx  xx   xx   31   30    29
xx  xx   xx   32   xx    28
xx  xx   xx   33   xx    27
xx  xx   xx   34   xx    26
xx 5/17 4/16 3/15  14   13/25
x 0/6/18  1    2   xx   12/24
xx 7/19 8/20 9/21 10/22 11/23
2 (2,0) is 2 steps away from the origin, 3 (2,1) has a distance of 3. Next record distance is 11 (4,-1), distance 5. Next is 29 (4,5), distance 9.
		

Crossrefs

Programs

  • Mathematica
    step[n_] := Switch[n, 0, {1,0}, 1, {0,1}, 2, {-1,0}, 3, {0,-1}]; r = {0,0}; q = 0; s={}; rm=0; Do[p = NextPrime[q]; r += step[Mod[n, 4]] * (p-q); r1 = Total @ Abs @ r; If[r1 > rm, rm = r1; AppendTo[s, p]]; q = p, {n, 0, 3000}]; s (* Amiram Eldar, Aug 15 2019 *)
  • PARI
    upto(n) = {my(pos = [0, 0], rotateLeft = [0, -1; 1, 0], step = [1, 0], recordDistance = 0, q = 0, res = List(), i = 0); forprime(p = 2, n, pos += (p - q) * step; step *= rotateLeft; if(abs(pos[1]) + abs(pos[2]) > recordDistance, i++; recordDistance = abs(pos[1]) + abs(pos[2]); listput(res, p)); q = p); res} \\ David A. Corneth, Aug 15 2019
  • Python
    def prime(z):
        isPrime=True
        for y in range(2,int(z**0.5)+1) :
            if z%y==0:
                isPrime=False
                break
        return isPrime
    m,n,g,h=[],[],[1,0,-1,0],[0,1,0,-1]
    for c in range (2,10000):
        if prime(c)==True:
            m.append(c)
    ca,cb,cc=2,0,0
    for j in range(2,10000):
        if j in m:
            cc=cc+1
            cd,ce=g[cc%4],h[cc%4]
        ca,cb=ca+cd,cb+ce
        n.append([j+1,ca,cb,abs(ca)+abs(cb)])
    v=2
    for j in n:
        if j[3]>v and j[0] in m:
            print (j)
            v=j[3]
    

A343423 Prime numbers p such that Euclidean distance from origin to p in hexagonal grid sets a new record. Number '1' is placed at the origin and '2' at (1, 0). Number 'm' (m >= 3) is placed by moving one unit forward in the direction from 'm-2' to 'm-1', if m - 1 is not a prime; otherwise, making 1/6 turn counterclockwise at 'm-1' followed by moving one unit forward.

Original entry on oeis.org

2, 3, 5, 7, 11, 29, 31, 59, 89, 127, 131, 157, 191, 193, 223, 227, 251, 257, 409, 521, 719, 757, 797, 809, 877, 881, 967, 971, 1009, 1013, 1049, 1087, 1091, 1117, 1123, 1277, 1301, 1361, 1409, 1423, 1447, 1451, 1523, 1531, 1657, 1693, 1697, 1699, 5273, 5323
Offset: 1

Views

Author

Ya-Ping Lu, Apr 15 2021

Keywords

Examples

			Hexagonal grid with integers up to 85:
                         29<---28<---27<---26<-7,25<=6,24<==5/23
                        /                       /              \\
                      30                      8                4/22
                     /                       /                    \\
                  31,53<-52<---51<---50<--9,49<--48<---47         3,21
                  /  \                    /              \        /  \
                54    32                10               1,46--->2    20
               /        \              /                    \           \
           55,79<--78<-33,77<--76<-11,75<--74<---73          45          19
            //             \           \           \           \        /
        56,80               34          12          72          44    18
         //                   \           \           \        /  \  /
     57,81                     35          13--->14->15,71-->16-->17,43
      //                         \                    /           /
  58,82                           36                70          42
   //                               \              /           /
59,83                                37--->38->39,69-->40--->41
   \\                                           /
  60,84                                       68
     \\                                      /
    61,85--->62--->63--->64--->65--->66--->67
Prime number (p), square of the distance (s) from p to origin, and index (n) in the sequence for p up to 71 are:
p:  2  3  5  7  11  13  17  19  23  29  31  37  41  43  47  53   59   61  67  71
s:  1  3  7  9  13  13   9   7   7  37  43  31  19   9   1  43  109  109  43   7
n:  1  2  3  4   5  --  --  --  --   6   7  --  --  --  --  --    8   --  --  --
		

Crossrefs

Programs

  • Python
    from sympy import isprime
    dx = [2, 1, -1, -2, -1, 1]; dy = [0, 1, 1, 0, -1, -1]
    x = 0; y = 0; rec = 0; d = 0
    for n in range(2, 10001):
        if isprime(n-1) == 1: d += 1; d %= 6
        x += dx[d]; y += dy[d]; s = x*x + 3*y*y
        if isprime(n) == 1 and s > rec: print(n); rec = s
Showing 1-2 of 2 results.