%I #22 Aug 14 2017 11:44:53
%S 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,
%T 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,
%U 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
%N 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.
%C Records (A002450) and indices of records (A237661) are as following:
%C Records: 5, 21, 85, 341, 1365, 5461, 21845, ...
%C Indices: 3, 42, 75, 151, 2730, 7281, 14563, ...
%C See A238192 and A238193 for a slightly different version. - _T. D. Noe_, Feb 21 2014
%C Differs from A238192 at n = 5, 21, 85, 341, 1365, 5461, 21845, ... (A002450 without its two initial terms). - _Antti Karttunen_, Aug 13 2017
%H Antti Karttunen, <a href="/A237660/b237660.txt">Table of n, a(n) for n = 1..21845</a>
%H Kival Ngaokrajang, <a href="/A237660/a237660.pdf">Illustration for n = 1..20</a>
%H <a href="/index/3#3x1">Index entries for sequences related to 3x+1 (or Collatz) problem</a>
%t {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 *)
%o (Small Basic)
%o For nn = 1 To 200
%o n = nn
%o c1 = 0
%o c2 = 0
%o loop:
%o m2 = math.Remainder(n,2)
%o If m2 = 0 Then
%o n = n/2
%o c2 = c2 + 1
%o Else
%o n = n*3 + 1
%o c2 = 0
%o EndIf
%o a[c1] = n
%o c1 = c1 + 1
%o If n = 1 Then
%o If a[c1-c2-2] = "" then
%o a[c1-c2-2] = 0
%o EndIf
%o TextWindow.Write(a[c1-c2-2]+", ")
%o Goto stop
%o Else
%o Goto loop
%o EndIf
%o stop:
%o EndFor
%o (Scheme)
%o (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)))))
%o (define (A014682 n) (if (even? n) (/ n 2) (/ (+ n n n 1) 2)))
%o ;; _Antti Karttunen_, Aug 13 2017
%o (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
%Y Cf. A002450, A237661, A238192, A238193.
%K nonn
%O 1,3
%A _Kival Ngaokrajang_, Feb 11 2014
%E Edited by _N. J. A. Sloane_, Feb 20 2014
|