OFFSET
1,1
COMMENTS
This sequence differs from A309755 where the Euclidean distance is used.
LINKS
Pieter Post, Table of n, a(n) for n = 1..166
EXAMPLE
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.
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 *)
PROG
(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]
(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
CROSSREFS
KEYWORD
nonn
AUTHOR
Pieter Post, Aug 13 2019
STATUS
approved