cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

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.

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