A237660 Consider the Collatz trajectory of n; if all terms except n and 1 are even then a(n) = 0, otherwise a(n) is the last odd number before 1.
0, 0, 5, 0, 0, 5, 5, 0, 5, 5, 5, 5, 5, 5, 5, 0, 5, 5, 5, 5, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 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, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 85, 5, 5, 5, 5, 5, 5, 5, 5, 21, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 85
Offset: 1
Keywords
Links
- Antti Karttunen, Table of n, a(n) for n = 1..21845
- Kival Ngaokrajang, Illustration for n = 1..20
- Index entries for sequences related to 3x+1 (or Collatz) problem
Programs
-
Mathematica
{0}~Join~Table[If[AllTrue[#, EvenQ], 0, SelectFirst[Reverse@ #, OddQ]] &@ Most@ Rest@ NestWhileList[If[EvenQ@ #, #/2, (3 # + 1)/2] &, n, # > 1 &], {n, 2, 113}] (* Michael De Vlieger, Aug 14 2017 *)
-
PARI
a(n)=my(k); if(n%2, n=3*n+1); n>>=valuation(n,2); if(n==1, return(0)); k=n; while(1, n+=(n+1)>>1; n>>=valuation(n,2); if(n==1, return(k), k=n)) \\ Charles R Greathouse IV, Aug 14 2017
-
Scheme
(define (A237660 n) (let loop ((n (A014682 n)) (last-odd 0)) (if (= 1 n) last-odd (loop (A014682 n) (if (odd? n) n last-odd))))) (define (A014682 n) (if (even? n) (/ n 2) (/ (+ n n n 1) 2))) ;; Antti Karttunen, Aug 13 2017
Extensions
Edited by N. J. A. Sloane, Feb 20 2014
Comments