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.

Showing 1-10 of 13 results. Next

A006667 Number of tripling steps to reach 1 from n in '3x+1' problem, or -1 if 1 is never reached.

Original entry on oeis.org

0, 0, 2, 0, 1, 2, 5, 0, 6, 1, 4, 2, 2, 5, 5, 0, 3, 6, 6, 1, 1, 4, 4, 2, 7, 2, 41, 5, 5, 5, 39, 0, 8, 3, 3, 6, 6, 6, 11, 1, 40, 1, 9, 4, 4, 4, 38, 2, 7, 7, 7, 2, 2, 41, 41, 5, 10, 5, 10, 5, 5, 39, 39, 0, 8, 8, 8, 3, 3, 3, 37, 6, 42, 6, 3, 6, 6, 11, 11, 1, 6, 40, 40, 1, 1, 9, 9, 4, 9, 4, 33, 4, 4, 38
Offset: 1

Views

Author

Keywords

Comments

A075680, which gives the values for odd n, isolates the essential behavior of this sequence. - T. D. Noe, Jun 01 2006
A033959 and A033958 give record values and where they occur. - Reinhard Zumkeller, Jan 08 2014

References

  • J.-P. Allouche and J. Shallit, Automatic Sequences, Cambridge Univ. Press, 2003, p. 204, Problem 22.
  • R. K. Guy, Unsolved Problems in Number Theory, E16.
  • N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).

Crossrefs

Equals A078719(n)-1.

Programs

  • Haskell
    a006667 = length . filter odd . takeWhile (> 2) . (iterate a006370)
    a006667_list = map a006667 [1..]
    -- Reinhard Zumkeller, Oct 08 2011
    
  • Maple
    a:= proc(n) option remember; `if`(n<2, 0,
          `if`(n::even, a(n/2), 1+a(3*n+1)))
        end:
    seq(a(n), n=1..100);  # Alois P. Heinz, Aug 08 2023
  • Mathematica
    Table[Count[Differences[NestWhileList[If[EvenQ[#],#/2,3#+1]&,n,#>1&]], ?Positive], {n,100}] (* _Harvey P. Dale, Nov 14 2011 *)
  • PARI
    for(n=2,100,s=n; t=0; while(s!=1,if(s%2==0,s=s/2,s=(3*s+1)/2; t++); if(s==1,print1(t,","); ); ))
    
  • Python
    def a(n):
        if n==1: return 0
        x=0
        while True:
            if n%2==0: n/=2
            else:
                n = 3*n + 1
                x+=1
            if n<2: break
        return x
    print([a(n) for n in range(1, 101)]) # Indranil Ghosh, Apr 14 2017

Formula

a(1) = 0, a(n) = a(n/2) if n is even, a(n) = a(3n+1)+1 if n>1 is odd. The Collatz conjecture is that this defines a(n) for all n >= 1.
a(n) = A078719(n) - 1; a(A000079(n))=0; a(A062052(n))=1; a(A062053(n))=2; a(A062054(n))=3; a(A062055(n))=4; a(A062056(n))=5; a(A062057(n))=6; a(A062058(n))=7; a(A062059(n))=8; a(A062060(n))=9. - Reinhard Zumkeller, Oct 08 2011
a(n*2^k) = a(n), for all k >= 0. - L. Edson Jeffery, Aug 11 2014
a(n) = floor(log(2^A006666(n)/n)/log(3)). - Joe Slater, Aug 30 2017
a(n) = a(A085062(n)) + A007814(n+1) for n >= 2. - Alan Michael Gómez Calderón, Feb 07 2025
From Alan Michael Gómez Calderón, Mar 31 2025: (Start)
a(n) = a(A139391(n)) + (n mod 2) for n >= 2;
a(n) = a(A139391(A000265(n))) - A209229(n) + 1 for n >= 2;
a(n) = a(A000265(A139391(n))) + (n mod 2) for n >= 2. (End)

Extensions

More terms from Larry Reeves (larryr(AT)acm.org), Apr 27 2001
"Escape clause" added to definition by N. J. A. Sloane, Jun 06 2017

A078719 Number of odd terms among n, f(n), f(f(n)), ...., 1 for the Collatz function (that is, until reaching "1" for the first time), or -1 if 1 is never reached.

Original entry on oeis.org

1, 1, 3, 1, 2, 3, 6, 1, 7, 2, 5, 3, 3, 6, 6, 1, 4, 7, 7, 2, 2, 5, 5, 3, 8, 3, 42, 6, 6, 6, 40, 1, 9, 4, 4, 7, 7, 7, 12, 2, 41, 2, 10, 5, 5, 5, 39, 3, 8, 8, 8, 3, 3, 42, 42, 6, 11, 6, 11, 6, 6, 40, 40, 1, 9, 9, 9, 4, 4, 4, 38, 7, 43, 7, 4, 7, 7, 12, 12, 2, 7, 41, 41, 2, 2, 10, 10, 5, 10, 5, 34, 5, 5, 39
Offset: 1

Views

Author

Joseph L. Pe, Dec 20 2002

Keywords

Comments

The Collatz function (related to the "3x+1 problem") is defined by: f(n) = n/2 if n is even; f(n) = 3n + 1 if n is odd. A famous conjecture states that n, f(n), f(f(n)), .... eventually reaches 1.
a(n) = A006667(n) + 1; a(A000079(n))=1; a(A062052(n))=2; a(A062053(n))=3; a(A062054(n))=4; a(A062055(n))=5; a(A062056(n))=6; a(A062057(n))=7; a(A062058(n))=8; a(A062059(n))=9; a(A062060(n))=10. - Reinhard Zumkeller, Oct 08 2011
The count includes also the starting value n if it is odd. See A286380 for the version which never includes n itself. - Antti Karttunen, Aug 10 2017

Examples

			The terms n, f(n), f(f(n)), ...., 1 for n = 12 are: 12, 6, 3, 10, 5, 16, 8, 4, 2, 1, of which 3 are odd. Hence a(12) = 3.
		

Crossrefs

Programs

  • Haskell
    a078719 =
       (+ 1) . length . filter odd . takeWhile (> 2) . (iterate a006370)
    a078719_list = map a078719 [1..]
    -- Reinhard Zumkeller, Oct 08 2011
    
  • Maple
    a:= proc(n) option remember; `if`(n<2, 1,
          `if`(n::even, a(n/2), 1+a(3*n+1)))
        end:
    seq(a(n), n=1..94);  # Alois P. Heinz, Jan 17 2025
  • Mathematica
    f[n_] := Module[{a, i, o}, i = n; o = 1; a = {}; While[i > 1, If[Mod[i, 2] == 1, o = o + 1]; a = Append[a, i]; i = f[i]]; o]; Table[f[i], {i, 1, 100}]
    Table[Count[NestWhileList[If[EvenQ[#], #/2, 3 # + 1] &, n, # > 1 &], ?OddQ], {n, 94}] (* _Jayanta Basu, Jun 15 2013 *)
  • PARI
    a(n) = {my(x=n, v=List([])); while(x>1, if(x%2==0, x=x/2, listput(v, x); x=3*x+1)); 1+#v;} \\ Jinyuan Wang, Dec 29 2019

Formula

a(n) = A286380(n) + A000035(n). - Antti Karttunen, Aug 10 2017
a(n) = A258145(A003602(n)-1). - Alan Michael Gómez Calderón, Sep 15 2024

Extensions

"Escape clause" added to definition by N. J. A. Sloane, Jun 06 2017

A062052 Numbers with exactly 2 odd integers in their Collatz (or 3x+1) trajectory.

Original entry on oeis.org

5, 10, 20, 21, 40, 42, 80, 84, 85, 160, 168, 170, 320, 336, 340, 341, 640, 672, 680, 682, 1280, 1344, 1360, 1364, 1365, 2560, 2688, 2720, 2728, 2730, 5120, 5376, 5440, 5456, 5460, 5461, 10240, 10752, 10880, 10912, 10920, 10922, 20480, 21504, 21760, 21824
Offset: 1

Views

Author

Keywords

Comments

The Collatz (or 3x+1) function is f(x) = x/2 if x is even, 3x+1 if x is odd.
The Collatz trajectory of n is obtained by applying f repeatedly to n until 1 is reached.
The sequence consists of terms of A002450 and their 2^k multiples. The first odd integer in the trajectory is one of the terms of A002450 and the second odd one is the terminal 1. - Antti Karttunen, Feb 21 2006
This sequence looks to appear first in the literature on page 1285 in R. E. Crandall.

Examples

			The Collatz trajectory of 5 is (5,16,8,4,2,1), which contains 2 odd integers.
		

Crossrefs

Is this a subset of A115774?
Column k=2 of A354236.

Programs

  • Haskell
    import Data.List (elemIndices)
    a062052 n = a062052_list !! (n-1)
    a062052_list = map (+ 1) $ elemIndices 2 a078719_list
    -- Reinhard Zumkeller, Oct 08 2011
    
  • Mathematica
    Collatz[n_] := NestWhileList[If[EvenQ[#], #/2, 3 # + 1] &, n, # > 1 &]; countOdd[lst_] := Length[Select[lst, OddQ]]; Select[Range[22000], countOdd[Collatz[#]] == 2 &] (* T. D. Noe, Dec 03 2012 *)
  • PARI
    for(n=2,100000,s=n; t=0; while(s!=1,if(s%2==0,s=s/2,s=3*s+1; t++); if(s*t==1,print1(n,","); ); ))
    
  • Python
    def a(n):
        l=[n, ]
        while True:
            if n%2==0: n//=2
            else: n = 3*n + 1
            if n not in l:
                l.append(n)
                if n<2: break
            else: break
        return len([i for i in l if i % 2])
    print([n for n in range(1, 22001) if a(n)==2]) # Indranil Ghosh, Apr 14 2017

Formula

A078719(a(n)) = 2; A006667(a(n)) = 1.
a(n) = 2^x * (4^y - 1)/3 where x = A122196(n) - 1 and y = A122197(n) + 1. - Alan Michael Gómez Calderón, Jan 16 2025 after Antti Karttunen

A354236 A(n,k) is the n-th number m such that the Collatz (or 3x+1) trajectory starting at m contains exactly k odd integers; square array A(n,k), n>=1, k>=1, read by antidiagonals.

Original entry on oeis.org

1, 5, 2, 3, 10, 4, 17, 6, 20, 8, 11, 34, 12, 21, 16, 7, 22, 35, 13, 40, 32, 9, 14, 23, 68, 24, 42, 64, 25, 18, 15, 44, 69, 26, 80, 128, 33, 49, 19, 28, 45, 70, 48, 84, 256, 43, 65, 50, 36, 29, 46, 75, 52, 85, 512, 57, 86, 66, 51, 37, 30, 88, 136, 53, 160, 1024
Offset: 1

Views

Author

Alois P. Heinz, May 20 2022

Keywords

Examples

			Square array A(n,k) begins:
    1,   5,  3,  17, 11,  7,  9,  25,  33,  43, ...
    2,  10,  6,  34, 22, 14, 18,  49,  65,  86, ...
    4,  20, 12,  35, 23, 15, 19,  50,  66,  87, ...
    8,  21, 13,  68, 44, 28, 36,  51,  67,  89, ...
   16,  40, 24,  69, 45, 29, 37,  98, 130, 172, ...
   32,  42, 26,  70, 46, 30, 38,  99, 131, 173, ...
   64,  80, 48,  75, 88, 56, 72, 100, 132, 174, ...
  128,  84, 52, 136, 90, 58, 74, 101, 133, 177, ...
  256,  85, 53, 138, 92, 60, 76, 102, 134, 178, ...
  512, 160, 96, 140, 93, 61, 77, 196, 260, 179, ...
		

Crossrefs

Row n=1 gives A092893(k-1).
Main diagonal gives A380244.

Programs

  • Maple
    b:= proc(n) option remember; irem(n, 2, 'r')+
          `if`(n=1, 0, b(`if`(n::odd, 3*n+1, r)))
        end:
    A:= proc() local h, p, q; p, q:= proc() [] end, 0;
          proc(n, k)
            if k=1 then return 2^(n-1) fi;
            while nops(p(k))
    				
  • Mathematica
    b[n_] := b[n] = Module[{q, r}, {q, r} = QuotientRemainder[n, 2]; r +
         If[n == 1, 0, b[If[OddQ[n], 3*n + 1, q]]]];
    A = Module[{h, p, q}, p[_] = {}; q = 0;
         Function[{n, k}, If[k == 1, 2^(n - 1)];
         While[Length[p[k]] < n, q = q + 1;
            h = b[q];
            p[h] = Append[p[h], q]];
         p[k][[n]]]];
    Table[Table[A[n, 1+d-n], {n, 1, d}], {d, 1, 12}] // Flatten (* Jean-François Alcover, Jun 02 2022, after Alois P. Heinz *)

Formula

A078719(A(n,k)) = k.

A062053 Numbers with exactly 3 odd integers in their Collatz (or 3x+1) trajectory.

Original entry on oeis.org

3, 6, 12, 13, 24, 26, 48, 52, 53, 96, 104, 106, 113, 192, 208, 212, 213, 226, 227, 384, 416, 424, 426, 452, 453, 454, 768, 832, 848, 852, 853, 904, 906, 908, 909, 1536, 1664, 1696, 1704, 1706, 1808, 1812, 1813, 1816, 1818, 3072, 3328, 3392, 3408, 3412, 3413, 3616
Offset: 1

Views

Author

Keywords

Comments

The Collatz (or 3x+1) function is f(x) = x/2 if x is even, 3x+1 if x is odd (A006370).
The Collatz trajectory of n is obtained by applying f repeatedly to n until 1 is reached.
A078719(a(n)) = 3; A006667(a(n)) = 2.

Examples

			The Collatz trajectory of 3 is (3,10,5,16,8,4,2,1), which contains 3 odd integers.
		

References

  • J. R. Goodwin, Results on the Collatz Conjecture, Sci. Ann. Comput. Sci. 13 (2003) pp. 1-16
  • J. Shallit and D. Wilson, The "3x+1" Problem and Finite Automata, Bulletin of the EATCS #46 (1992) pp. 182-185.

Crossrefs

Cf. A198584 (this sequence without the even numbers).
See also A198587.
Column k=3 of A354236.

Programs

  • Haskell
    import Data.List (elemIndices)
    a062053 n = a062053_list !! (n-1)
    a062053_list = map (+ 1) $ elemIndices 3 a078719_list
    -- Reinhard Zumkeller, Oct 08 2011
  • Mathematica
    Collatz[n_?OddQ] := (3n + 1)/2; Collatz[n_?EvenQ] := n/2; oddIntCollatzCount[n_] := Length[Select[NestWhileList[Collatz, n, # != 1 &], OddQ]]; Select[Range[4000], oddIntCollatzCount[#] == 3 &] (* Alonso del Arte, Oct 28 2011 *)

Formula

The two formulas giving this sequence are listed in Corollary 3.1 and Corollary 3.2 in J. R. Goodwin with the following caveats: the value x cannot equal zero in Corollary 3.2, one must multiply the formulas by all powers of 2 (2^1, 2^2, ...) to get the evens. - Jeffrey R. Goodwin, Oct 26 2011

A062055 Numbers with 5 odd integers in their Collatz (or 3x+1) trajectory.

Original entry on oeis.org

11, 22, 23, 44, 45, 46, 88, 90, 92, 93, 176, 180, 181, 184, 186, 201, 352, 360, 362, 368, 369, 372, 373, 401, 402, 403, 704, 720, 724, 725, 736, 738, 739, 744, 746, 753, 802, 803, 804, 805, 806, 1408, 1440, 1448, 1450, 1472, 1476, 1477, 1478, 1488, 1492, 1493, 1506
Offset: 1

Views

Author

Keywords

Comments

The Collatz (or 3x+1) function is f(x) = x/2 if x is even, 3x+1 if x is odd.
The Collatz trajectory of n is obtained by applying f repeatedly to n until 1 is reached.
A078719(a(n)) = 5; A006667(a(n)) = 4.

Examples

			The Collatz trajectory of 11 is (11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1), which contains 5 odd integers.
		

References

  • J. Shallit and D. Wilson, The "3x+1" Problem and Finite Automata, Bulletin of the EATCS #46 (1992) pp. 182-185.

Crossrefs

Column k=5 of A354236.

Programs

  • Haskell
    import Data.List (elemIndices)
    a062055 n = a062055_list !! (n-1)
    a062055_list = map (+ 1) $ elemIndices 5 a078719_list
    -- Reinhard Zumkeller, Oct 08 2011
  • Mathematica
    Collatz[n_] := NestWhileList[If[EvenQ[#], #/2, 3 # + 1] &, n, # > 1 &]; countOdd[lst_] := Length[Select[lst, OddQ]]; Select[Range[2000], countOdd[Collatz[#]] == 5 &] (* T. D. Noe, Dec 03 2012 *)

A062056 Numbers with 6 odd integers in their Collatz (or 3x+1) trajectory.

Original entry on oeis.org

7, 14, 15, 28, 29, 30, 56, 58, 60, 61, 112, 116, 117, 120, 122, 224, 232, 234, 240, 241, 244, 245, 267, 448, 464, 468, 469, 480, 482, 483, 488, 490, 497, 534, 535, 537, 896, 928, 936, 938, 960, 964, 965, 966, 976, 980, 981, 985, 994, 995, 1068, 1069, 1070, 1073
Offset: 1

Views

Author

Keywords

Comments

The Collatz (or 3x+1) function is f(x) = x/2 if x is even, 3x+1 if x is odd.
The Collatz trajectory of n is obtained by applying f repeatedly to n until 1 is reached.
A078719(a(n)) = 6; A006667(a(n)) = 5.

Examples

			The Collatz trajectory of 7 is (7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1), which contains 6 odd integers.
		

References

  • J. Shallit and D. Wilson, The "3x+1" Problem and Finite Automata, Bulletin of the EATCS #46 (1992) pp. 182-185.

Crossrefs

Column k=6 of A354236.

Programs

  • Haskell
    import Data.List (elemIndices)
    a062056 n = a062056_list !! (n-1)
    a062056_list = map (+ 1) $ elemIndices 6 a078719_list
    -- Reinhard Zumkeller, Oct 08 2011
  • Mathematica
    Collatz[n_] := NestWhileList[If[EvenQ[#], #/2, 3 # + 1] &, n, # > 1 &]; countOdd[lst_] := Length[Select[lst, OddQ]]; Select[Range[1000], countOdd[Collatz[#]] == 6 &] (* T. D. Noe, Dec 03 2012 *)

A062057 Numbers with 7 odd integers in their Collatz (or 3x+1) trajectory.

Original entry on oeis.org

9, 18, 19, 36, 37, 38, 72, 74, 76, 77, 81, 144, 148, 149, 152, 154, 162, 163, 288, 296, 298, 304, 308, 309, 321, 324, 325, 326, 331, 576, 592, 596, 597, 608, 616, 618, 625, 642, 643, 648, 650, 652, 653, 662, 663, 713, 715, 1152, 1184, 1192, 1194, 1216, 1232, 1236, 1237
Offset: 1

Views

Author

Keywords

Comments

The Collatz (or 3x+1) function is f(x) = x/2 if x is even, 3x+1 if x is odd.
The Collatz trajectory of n is obtained by applying f repeatedly to n until 1 is reached.
A078719(a(n)) = 7; A006667(a(n)) = 6.

Examples

			The Collatz trajectory of 9 is (9, 28, 14, 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1), which contains 7 odd integers.
		

References

  • J. Shallit and D. Wilson, The "3x+1" Problem and Finite Automata, Bulletin of the EATCS #46 (1992) pp. 182-185.

Crossrefs

Column k=7 of A354236.

Programs

  • Haskell
    import Data.List (elemIndices)
    a062057 n = a062057_list !! (n-1)
    a062057_list = map (+ 1) $ elemIndices 7 a078719_list
    -- Reinhard Zumkeller, Oct 08 2011
  • Mathematica
    Collatz[n_] := NestWhileList[If[EvenQ[#], #/2, 3 # + 1] &, n, # > 1 &]; countOdd[lst_] := Length[Select[lst, OddQ]]; Select[Range[1000], countOdd[Collatz[#]] == 7 &] (* T. D. Noe, Dec 03 2012 *)

A062058 Numbers with 8 odd integers in their Collatz (or 3x+1) trajectory.

Original entry on oeis.org

25, 49, 50, 51, 98, 99, 100, 101, 102, 196, 197, 198, 200, 202, 204, 205, 217, 392, 394, 396, 397, 400, 404, 405, 408, 410, 433, 434, 435, 441, 475, 784, 788, 789, 792, 794, 800, 808, 810, 816, 820, 821, 833, 857, 866, 867, 868, 869, 870, 875, 882, 883, 950, 951, 953
Offset: 1

Views

Author

Keywords

Comments

The Collatz (or 3x+1) function is f(x) = x/2 if x is even, 3x+1 if x is odd.
The Collatz trajectory of n is obtained by applying f repeatedly to n until 1 is reached.
A078719(a(n)) = 8; A006667(a(n)) = 7.

Examples

			The Collatz trajectory of 25 is (25, 76, 38, 19, 58, 29, 88, 44, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1), which contains 8 odd integers.
		

References

  • J. Shallit and D. Wilson, The "3x+1" Problem and Finite Automata, Bulletin of the EATCS #46 (1992) pp. 182-185.

Crossrefs

Column k=8 of A354236.

Programs

  • Haskell
    import Data.List (elemIndices)
    a062058 n = a062058_list !! (n-1)
    a062058_list = map (+ 1) $ elemIndices 8 a078719_list
    -- Reinhard Zumkeller, Oct 08 2011
  • Mathematica
    Collatz[n_] := NestWhileList[If[EvenQ[#], #/2, 3 # + 1] &, n, # > 1 &]; countOdd[lst_] := Length[Select[lst, OddQ]]; Select[Range[1000], countOdd[Collatz[#]] == 8 &] (* T. D. Noe, Dec 03 2012 *)

A062059 Numbers with 9 odd integers in their Collatz (or 3x+1) trajectory.

Original entry on oeis.org

33, 65, 66, 67, 130, 131, 132, 133, 134, 260, 261, 262, 264, 266, 268, 269, 273, 289, 520, 522, 524, 525, 528, 529, 532, 533, 536, 538, 546, 547, 555, 571, 577, 578, 579, 583, 633, 635, 1040, 1044, 1045, 1048, 1050, 1056, 1058, 1059, 1064, 1066, 1072, 1076, 1077
Offset: 1

Views

Author

Keywords

Comments

The Collatz (or 3x+1) function is f(x) = x/2 if x is even, 3x+1 if x is odd.
The Collatz trajectory of n is obtained by applying f repeatedly to n until 1 is reached.
A078719(a(n)) = 9; A006667(a(n)) = 8.

Examples

			The Collatz trajectory of 33 is (33, 100, 50, 25, 76, 38, 19, 58, 29, 88, 44, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1), which contains 9 odd integers.
		

References

  • J. Shallit and D. Wilson, The "3x+1" Problem and Finite Automata, Bulletin of the EATCS #46 (1992) pp. 182-185.

Crossrefs

Programs

  • Haskell
    import Data.List (elemIndices)
    a062059 n = a062059_list !! (n-1)
    a062059_list = map (+ 1) $ elemIndices 9 a078719_list
    -- Reinhard Zumkeller, Oct 08 2011
    
  • Mathematica
    Collatz[n_] := NestWhileList[If[EvenQ[#], #/2, 3 # + 1] &, n, # > 1 &]; countOdd[lst_] := Length[Select[lst, OddQ]]; Select[Range[1000], countOdd[Collatz[#]] == 9 &] (* T. D. Noe, Dec 03 2012 *)
  • Python
    def a(n):
        l=[n, ]
        while True:
            if n%2==0: n//=2
            else: n = 3*n + 1
            if n not in l:
                l+=[n, ]
                if n<2: break
            else: break
        return len([i for i in l if i%2])
    [n for n in range(30, 1101) if a(n)==9] # Indranil Ghosh, Apr 14 2017
Showing 1-10 of 13 results. Next