login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A293689 Position of the prime ant after n steps. If the value of the ant's position is prime, it steps to the right; if the value is composite, it divides by the least divisor, steps to the left, and adds the divisor. 1

%I #26 Aug 12 2022 09:18:05

%S 0,1,2,1,2,3,4,3,4,5,6,5,4,3,2,3,4,5,6,5,6,7,6,7,8,7,8,9,10,9,10,9,8,

%T 7,8,7,6,5,6,5,4,3,4,5,6,7,8,9,10,11,12,11,10,9,10,11,12,13,12,11,12,

%U 13,14,13,14,13,12,11,10,9,8,9,10,11,12,11,12,13

%N Position of the prime ant after n steps. If the value of the ant's position is prime, it steps to the right; if the value is composite, it divides by the least divisor, steps to the left, and adds the divisor.

%C a(n) gives the position after the n-th step on the infinite sequence (2, 3, 4, ...). If the value at the ant's position is prime, the ant steps to the right. If the value is composite, the ant divides the number by its least prime divisor, steps to the left, and adds the divisor to the new position.

%H Peter Kagey, <a href="/A293689/b293689.txt">Table of n, a(n) for n = 0..10000</a>

%H Code Golf Stack Exchange user Super Chafouin, <a href="https://codegolf.stackexchange.com/questions/144695/the-prime-ant">The Prime Ant</a>.

%e a(0) = 0:

%e 2 3 4 5 6 7 ...

%e ^ (prime; step to the right)

%e a(1) = 1:

%e 2 3 4 5 6 7 ...

%e ^ (prime; step to the right)

%e a(2) = 2:

%e 2 3 4 5 6 7 ...

%e ^ (composite; divide by 2, step to the left, add 2)

%e a(3) = 1:

%e 2 5 2 5 6 7 ...

%e ^ (prime; step to the right)

%e a(4) = 2:

%e 2 5 2 5 6 7 ...

%e ^

%t NestWhileList[If[PrimeQ[#2[[#1]] ], {#1 + 1, #2}, {#1 - 1, ReplacePart[#2, {#1 - 1 -> #2[[#1 - 1]] + #3, #1 -> #2[[#1]]/#3}]} & @@ {#1, #2, FactorInteger[#2[[#1]] ][[1, 1]]}] & @@ # &, {2, Range[10^2]}, First@ # < Length@ Last@ # &, 1, 78][[All, 1]] - 2 (* _Michael De Vlieger_, Oct 15 2017 *)

%K nonn,walk,look

%O 0,3

%A _Peter Kagey_, Oct 14 2017

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified April 18 21:46 EDT 2024. Contains 371781 sequences. (Running on oeis4.)