OFFSET
0,1
FORMULA
a(0) = 79; a(n) = 3*a(n - 1) + 1 if a(n - 1) is odd, a(n) = a(n - 1)/2 otherwise.
EXAMPLE
79 is odd, so it's followed by 3 * 79 + 1 = 238.
238 is even, so it's followed by 238/2 = 119.
MATHEMATICA
NestList[If[EvenQ[#], #/2, 3# + 1] &, 79, 100]
PROG
(Scheme, with memoization-macro definec)
(define (A006370 n) (if (even? n) (/ n 2) (+ 1 n n n))) ;; Image of n under the `3x+1' map.
;; Antti Karttunen, May 26 2015
(Magma) [n eq 1 select 79 else IsOdd(Self(n-1)) select 3*Self(n-1)+1 else Self(n-1) div 2: n in [1..100]]; // Vincenzo Librandi, May 27 2015
(Scala) def collatz(n: Int): Int = n % 2 match {
case 0 => n / 2
case _ => 3 * n + 1
}
def collatzSeq(n: Int): LazyList[Int] = LazyList.iterate(n)(collatz)
collatzSeq(79).take(100).toList // Alonso del Arte, Apr 26 2020
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
Alonso del Arte, May 19 2015
STATUS
approved