|
|
A258098
|
|
3x + 1 sequence starting at 79.
|
|
3
|
|
|
79, 238, 119, 358, 179, 538, 269, 808, 404, 202, 101, 304, 152, 76, 38, 19, 58, 29, 88, 44, 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
(list;
graph;
refs;
listen;
history;
text;
internal format)
|
|
|
OFFSET
|
0,1
|
|
LINKS
|
|
|
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.
(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)
|
|
CROSSREFS
|
|
|
KEYWORD
|
nonn,easy
|
|
AUTHOR
|
|
|
STATUS
|
approved
|
|
|
|