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.

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.

This page as a plain text file.
%I A309701 #38 Sep 17 2019 13:43:45
%S A309701 2,3,11,29,59,97,151,193,211,223,239,281,307,311,331,337,479,541,593,
%T A309701 613,631,641,659,877,881,907,911,997,1409,1861,1907,2267,2281,2287,
%U A309701 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
%N 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.
%C A309701 This sequence differs from A309755 where the Euclidean distance is used.
%H A309701 Pieter Post, <a href="/A309701/b309701.txt">Table of n, a(n) for n = 1..166</a>
%e A309701 Grid of the first 34 steps. 0 represents (0,0).
%e A309701 xx  xx   xx   31   30    29
%e A309701 xx  xx   xx   32   xx    28
%e A309701 xx  xx   xx   33   xx    27
%e A309701 xx  xx   xx   34   xx    26
%e A309701 xx 5/17 4/16 3/15  14   13/25
%e A309701 x 0/6/18  1    2   xx   12/24
%e A309701 xx 7/19 8/20 9/21 10/22 11/23
%e A309701 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.
%t A309701 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 *)
%o A309701 (Python)
%o A309701 def prime(z):
%o A309701     isPrime=True
%o A309701     for y in range(2,int(z**0.5)+1) :
%o A309701         if z%y==0:
%o A309701             isPrime=False
%o A309701             break
%o A309701     return isPrime
%o A309701 m,n,g,h=[],[],[1,0,-1,0],[0,1,0,-1]
%o A309701 for c in range (2,10000):
%o A309701     if prime(c)==True:
%o A309701         m.append(c)
%o A309701 ca,cb,cc=2,0,0
%o A309701 for j in range(2,10000):
%o A309701     if j in m:
%o A309701         cc=cc+1
%o A309701         cd,ce=g[cc%4],h[cc%4]
%o A309701     ca,cb=ca+cd,cb+ce
%o A309701     n.append([j+1,ca,cb,abs(ca)+abs(cb)])
%o A309701 v=2
%o A309701 for j in n:
%o A309701     if j[3]>v and j[0] in m:
%o A309701         print (j)
%o A309701         v=j[3]
%o A309701 (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
%Y A309701 Cf. A000040, A309755.
%K A309701 nonn
%O A309701 1,1
%A A309701 _Pieter Post_, Aug 13 2019