%I #29 Nov 17 2021 17:02:22
%S 9,28,14,7,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,1,4,2,1,4,2,1,4,2,
%T 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,2,1,
%U 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
%N 3x+1 sequence beginning at 9.
%H Colin Barker, <a href="/A033479/b033479.txt">Table of n, a(n) for n = 0..1000</a>
%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_, Oct 04 2019: (Start)
%F G.f.: (9 + 28*x + 14*x^2 - 2*x^3 - 6*x^4 - 3*x^5 + 27*x^6 - 5*x^7 + 41*x^8 - 8*x^9 - 4*x^10 - 12*x^11 - 6*x^12 - 3*x^13 - 35*x^14 - 4*x^15 - 2*x^16 - x^17 - 14*x^18 - 7*x^19) / ((1 - x)*(1 + x + x^2)).
%F a(n) = a(n-3) for n>19.
%F (End)
%e 9 is odd, so the next term is 3*9 + 1 = 28.
%e 28 is even, so the next term is 28/2 = 14.
%t NestList[If[EvenQ[#], #/2, 3# + 1] &, 9, 100] (* _Harvey P. Dale_, Dec 16 2012 *)
%o (Scala) def collatz(n: Int): Int = (n % 2) match {
%o case 0 => n / 2
%o case 1 => 3 * n + 1
%o }
%o import scala.collection.mutable.ListBuffer
%o val start = 9; var curr = start; var trajectory = new ListBuffer[Int]()
%o for (_ <- 1 to 100) {
%o trajectory += curr; curr = collatz(curr)
%o }
%o trajectory // _Alonso del Arte_, Jun 02 2019
%o (PARI) Vec((9 + 28*x + 14*x^2 - 2*x^3 - 6*x^4 - 3*x^5 + 27*x^6 - 5*x^7 + 41*x^8 - 8*x^9 - 4*x^10 - 12*x^11 - 6*x^12 - 3*x^13 - 35*x^14 - 4*x^15 - 2*x^16 - x^17 - 14*x^18 - 7*x^19) / ((1 - x)*(1 + x + x^2)) + O(x^80)) \\ _Colin Barker_, Oct 04 2019
%o (Python)
%o from itertools import accumulate
%o def f(x, _): return x//2 if x%2 == 0 else 3*x+1
%o print(list(accumulate([9]*92, f))) # _Michael S. Branicky_, Sep 28 2021
%Y Cf. A070165.
%Y Row 9 of A347270.
%K nonn,easy
%O 0,1
%A _Jeff Burch_