OFFSET
0,3
LINKS
M. F. Hasler, Turtle(prime) walk after 25 steps.
M. F. Hasler, Turtle(prime) walk after 60 steps.
M. F. Hasler, Turtle(prime) walk after the 99th step, drawn in red.
EXAMPLE
The cursor starts for n=0 at the origin (a(0)=a(1)=0), facing East (= direction of the x-axis). At step 1, prime(1)=2 leads to a turn left by 2*90 degrees (now facing West), then a step of two units into the new direction, to x+iy = -2, thus a(2)=-2, a(3)=0. Prime(2)=3 leads to a turn left by 3*90 degrees, now facing North, and a step of 3 units in that direction, to x+iy = -2+3i, therefore a(4)=-2, a(5)=3.
MATHEMATICA
Turtle[v_] := Module[{p, L, d}, p=0; L={p}; d=1; For[i=1, i <= Length[v], i++, d *= I^v[[i]]; AppendTo[L, p += d*v[[i]] ] ]; L]; {Re[#], Im[#]}& /@ Turtle[Prime /@ Range[60]] // Flatten (* Jean-François Alcover, Dec 11 2013, translated from PARI *)
PROG
(PARI) Turtle(v, p=0, L=[p], d=1)=for(i=1, #v, d*=I^v[i]; L=concat(L, p+=d*v[i])); L
(PARI) a(nMax)=concat(apply(z->[real(z), imag(z)], Turtle(primes(nMax))))
CROSSREFS
KEYWORD
sign,walk
AUTHOR
M. F. Hasler, Dec 08 2013
STATUS
approved