A263716 Irregular triangle read by rows: numbers in the Collatz conjecture in the order of their first appearance.
1, 2, 3, 10, 5, 16, 8, 4, 6, 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 9, 28, 14, 12, 15, 46, 23, 70, 35, 106, 53, 160, 80, 18, 19, 58, 29, 88, 44, 21, 64, 32, 24, 25, 76, 38, 27, 82, 41, 124, 62, 31, 94, 47, 142, 71, 214, 107, 322, 161, 484, 242, 121, 364, 182
Offset: 0
Examples
Triangle begins: 1; 2; 3, 10, 5, 16, 8, 4; ... The Collatz trajectories for the first five positive integers are {1}, {2, 1}, {3, 10, 5, 16, 8, 4, 2, 1}, {4, 2, 1}, {5, 16, 8, 4, 2, 1}. From {2, 1} we delete 1 because it has already occurred. From {3, 10, 5, ..., 4, 2, 1} we delete {2, 1} because both numbers have already occurred. We completely get rid of {4, 2, 1} because it has already occurred as the tail end of {3, 10, 5, ...}, and we also completely get rid of {5, 16, 8, ...} for the same reason. This leaves us with {1}, {2}, {3, 10, 5, 16, 8, 4}, thus accounting for the first eight terms of this sequence.
Links
Programs
-
Mathematica
collatz[n_] := NestWhileList[If[EvenQ[#], #/2, 3 # + 1] &, n, # > 1 &]; DeleteDuplicates[Flatten[Table[collatz[n], {n, 20}]]] (* Alonso del Arte, Oct 24 2015 *)
-
Sidef
func collatz(n) is cached { # automatically memoized function say n; # prints the first unseen numbers n.is_one ? 0 : (n.is_even ? collatz(n/2) : collatz(3*n + 1)); } range(1, Math.inf).each { |i| collatz(i) }
Formula
row(n) = {
if seen[n]: stop
else: write(n) and do:
| n is one: stop
| n is odd: n <- 3*n+1
| n is even: n <- n/2
}
Comments