%I #38 Sep 08 2022 08:44:36
%S 81,244,122,61,184,92,46,23,70,35,106,53,160,80,40,20,10,5,16,8,4,2,1,
%T 4,2,1,4,2,1,4,2,1,4,2,1,4,2,1,4,2,1,4,2,1,4,2,1,4,2,1,4,2,1,4,2,1,4,
%U 2,1,4,2,1,4,2,1,4,2,1,4,2,1
%N 3x+1 sequence starting at 81.
%D R. K. Guy, Unsolved Problems in Number Theory, E16.
%H Vincenzo Librandi, <a href="/A008876/b008876.txt">Table of n, a(n) for n = 0..200</a>
%H Darrell Cox, <a href="https://cs.uwaterloo.ca/journals/JIS/VOL15/Cox/cox10.html">The 3n + 1 Problem: A Probabilistic Approach</a>, Journal of Integer Sequences, Vol. 15 (2012), #12.5.2.
%H <a href="/index/3#3x1">Index entries for sequences related to 3x+1 (or Collatz) problem</a>
%H <a href="/index/Rec#order_03">Index entries for linear recurrences with constant coefficients</a>, signature (0,0,1).
%F From _Colin Barker_, Apr 27 2020: (Start)
%F G.f.: (81 + 244*x + 122*x^2 - 20*x^3 - 60*x^4 - 30*x^5 - 15*x^6 - 161*x^7 - 22*x^8 - 11*x^9 + 83*x^10 - 17*x^11 + 125*x^12 - 26*x^13 - 13*x^14 - 140*x^15 - 70*x^16 - 35*x^17 - 4*x^18 - 2*x^19 - x^20 - 14*x^21 - 7*x^22) / ((1 - x)*(1 + x + x^2)).
%F a(n) = a(n-3) for n>22.
%F (End)
%p f := proc(n) option remember; if n = 0 then 81; elif f(n-1) mod 2 = 0 then f(n-1)/2 else 3*f(n-1)+1; fi; end;
%t NestList[If[EvenQ[#], #/2, 3# + 1]&, 81, 100] (* _Vincenzo Librandi_, Jul 29 2014 *)
%o (Haskell)
%o a008876 n = a008876_list !! n
%o a008876_list = 81 : iterate a006370 81
%o -- _Reinhard Zumkeller_, Aug 30 2012
%o (Magma) [n eq 1 select 81 else IsOdd(Self(n-1)) select 3*Self(n-1)+1 else Self(n-1) div 2: n in [1..70]]; // _Vincenzo Librandi_, Jul 29 2014
%o (Scala) def collatz(n: Int): Int = n % 2 match { case 0 => n / 2; case _ => 3 * n + 1 }
%o def collatzSeq(n: Int): LazyList[Int] = LazyList.iterate(n)(collatz)
%o collatzSeq(81).take(100).toList // _Alonso del Arte_, Apr 24 2020
%o (PARI) Vec((81 + 244*x + 122*x^2 - 20*x^3 - 60*x^4 - 30*x^5 - 15*x^6 - 161*x^7 - 22*x^8 - 11*x^9 + 83*x^10 - 17*x^11 + 125*x^12 - 26*x^13 - 13*x^14 - 140*x^15 - 70*x^16 - 35*x^17 - 4*x^18 - 2*x^19 - x^20 - 14*x^21 - 7*x^22) / ((1 - x)*(1 + x + x^2)) + O(x^70)) \\ _Colin Barker_, Apr 27 2020
%Y Cf. A006370.
%Y Row 81 of A347270.
%K nonn,easy
%O 0,1
%A _N. J. A. Sloane_