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.

A033479 3x+1 sequence beginning at 9.

Original entry on oeis.org

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

Views

Author

Keywords

Examples

			9 is odd, so the next term is 3*9 + 1 = 28.
28 is even, so the next term is 28/2 = 14.
		

Crossrefs

Cf. A070165.
Row 9 of A347270.

Programs

  • Mathematica
    NestList[If[EvenQ[#], #/2, 3# + 1] &, 9, 100] (* Harvey P. Dale, Dec 16 2012 *)
  • 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
  • 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
    

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)