login
A033479
3x+1 sequence beginning at 9.
12
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, 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, 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
OFFSET
0,1
FORMULA
From Colin Barker, Oct 04 2019: (Start)
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)).
a(n) = a(n-3) for n>19.
(End)
EXAMPLE
9 is odd, so the next term is 3*9 + 1 = 28.
28 is even, so the next term is 28/2 = 14.
MATHEMATICA
NestList[If[EvenQ[#], #/2, 3# + 1] &, 9, 100] (* Harvey P. Dale, Dec 16 2012 *)
PROG
(Scala) def collatz(n: Int): Int = (n % 2) match {
case 0 => n / 2
case 1 => 3 * n + 1
}
import scala.collection.mutable.ListBuffer
val start = 9; var curr = start; var trajectory = new ListBuffer[Int]()
for (_ <- 1 to 100) {
trajectory += curr; curr = collatz(curr)
}
trajectory // Alonso del Arte, Jun 02 2019
(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
(Python)
from itertools import accumulate
def f(x, _): return x//2 if x%2 == 0 else 3*x+1
print(list(accumulate([9]*92, f))) # Michael S. Branicky, Sep 28 2021
CROSSREFS
Cf. A070165.
Row 9 of A347270.
Sequence in context: A351266 A369721 A369759 * A254139 A034116 A031454
KEYWORD
nonn,easy
AUTHOR
STATUS
approved