A306577 Last odd number reached by n before 1 through Collatz iteration, where a(n) = 1 when no other odd number is reached, or -1 if 1 is never reached.
1, 1, 5, 1, 5, 5, 5, 1, 5, 5, 5, 5, 5, 5, 5, 1, 5, 5, 5, 5, 21, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 5, 5, 5, 5, 5, 5, 5, 5, 5, 21, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 85, 5, 5, 5, 5, 5, 5, 5, 5, 21, 85, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5
Offset: 1
Examples
From _Felix Fröhlich_, Apr 25 2019: (Start) For n = 16: The Collatz trajectory of 16 up to the first occurrence of 1 is 16, 8, 4, 2, 1. The trajectory does not include any odd number other than 1, so a(16) = 1. For n = 42: The Collatz trajectory of 42 up to the first occurrence of 1 is 21, 64, 32, 16, 8, 4, 2, 1. The last odd number occurring before 1 is 21, so a(42) = 21. (End)
Links
- Antti Karttunen, Table of n, a(n) for n = 1..14563
- Antti Karttunen, Data supplement: n, a(n) computed for n = 1..87381
Programs
-
Mathematica
Array[If[! IntegerQ@ #, 1, #] &@ SelectFirst[Reverse@ Most@ NestWhileList[If[EvenQ@ #, #/2, 3 # + 1] &, #, # > 1 &], OddQ] &, 100] (* Michael De Vlieger, Mar 05 2019 *)
-
PARI
next_iter(n) = if(n%2==0, return(n/2), return(3*n+1)) a(n) = my(x=n, oddnum=1); while(x!=1, if(x%2==1, oddnum=x); x=next_iter(x)); oddnum \\ Felix Fröhlich, Apr 25 2019
Extensions
Escape clause added to the definition by Antti Karttunen, Dec 05 2021
Comments