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

A125195 Records in A127885.

Original entry on oeis.org

0, 1, 7, 8, 16, 17, 20, 23, 31, 32, 38, 46, 47, 50, 53, 56, 59
Offset: 1

Views

Author

David Applegate and N. J. A. Sloane, Feb 06 2007

Keywords

Crossrefs

A125686 Where records occur in A127885.

Original entry on oeis.org

1, 2, 3, 6, 7, 14, 19, 25, 31, 62, 107, 127, 255, 339, 479, 639, 799
Offset: 1

Views

Author

David Applegate and N. J. A. Sloane, Feb 06 2007

Keywords

Crossrefs

A125719 A127885(prime(n)).

Original entry on oeis.org

1, 7, 5, 16, 14, 9, 12, 20, 15, 18, 31, 13, 21, 21, 29, 11, 24, 19, 27, 27, 27, 27, 22, 22, 30, 25, 30, 38, 25, 12, 46, 20, 28, 33, 15, 15, 28, 23, 23, 23, 23, 18, 44, 31, 18, 31, 31, 44, 13, 26, 26, 26, 21, 39, 34, 34, 21, 34, 16, 34, 34, 29, 29, 29, 29, 29, 24, 37, 37, 24, 24, 24, 37
Offset: 1

Views

Author

David Applegate and N. J. A. Sloane, Feb 06 2007

Keywords

Crossrefs

A072761 Erroneous version of A127885.

Original entry on oeis.org

0, 1, 7, 2, 5, 8, 8, 3, 11, 5, 9, 9, 8, 9, 9, 4, 9, 12, 14, 7, 7, 11, 12, 10
Offset: 1

Views

Author

N. J. A. Sloane, May 26 2012

Keywords

References

  • M. J. Halm, Sequences (Re)discovered, Mpossibilities 81 (Aug. 2002), p. 1.

Crossrefs

A006577 Number of halving and tripling steps to reach 1 in '3x+1' problem, or -1 if 1 is never reached.

Original entry on oeis.org

0, 1, 7, 2, 5, 8, 16, 3, 19, 6, 14, 9, 9, 17, 17, 4, 12, 20, 20, 7, 7, 15, 15, 10, 23, 10, 111, 18, 18, 18, 106, 5, 26, 13, 13, 21, 21, 21, 34, 8, 109, 8, 29, 16, 16, 16, 104, 11, 24, 24, 24, 11, 11, 112, 112, 19, 32, 19, 32, 19, 19, 107, 107, 6, 27, 27, 27, 14, 14, 14, 102, 22
Offset: 1

Views

Author

Keywords

Comments

The 3x+1 or Collatz problem is as follows: start with any number n. If n is even, divide it by 2, otherwise multiply it by 3 and add 1. Do we always reach 1? This is a famous unsolved problem. It is conjectured that the answer is yes.
It seems that about half of the terms satisfy a(i) = a(i+1). For example, up to 10000000, 4964705 terms satisfy this condition.
n is an element of row a(n) in triangle A127824. - Reinhard Zumkeller, Oct 03 2012
The number of terms that satisfy a(i) = a(i+1) for i being a power of ten from 10^1 through 10^10 are: 0, 31, 365, 4161, 45022, 477245, 4964705, 51242281, 526051204, 5378743993. - John Mason, Mar 02 2018
5 seems to be the only number whose value matches its total number of steps (checked to n <= 10^9). - Peter Woodward, Feb 15 2021

Examples

			a(5)=5 because the trajectory of 5 is (5,16,8,4,2,1).
		

References

  • 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

See A070165 for triangle giving trajectories of n = 1, 2, 3, ....

Programs

  • Haskell
    import Data.List (findIndex)
    import Data.Maybe (fromJust)
    a006577 n = fromJust $ findIndex (n `elem`) a127824_tabf
    -- Reinhard Zumkeller, Oct 04 2012, Aug 30 2012
    
  • Maple
    A006577 := proc(n)
            local a,traj ;
            a := 0 ;
            traj := n ;
            while traj > 1 do
                    if type(traj,'even') then
                            traj := traj/2 ;
                    else
                            traj := 3*traj+1 ;
                    end if;
                    a := a+1 ;
            end do:
            return a;
    end proc: # R. J. Mathar, Jul 08 2012
  • Mathematica
    f[n_] := Module[{a=n,k=0}, While[a!=1, k++; If[EvenQ[a], a=a/2, a=a*3+1]]; k]; Table[f[n],{n,4!}] (* Vladimir Joseph Stephan Orlovsky, Jan 08 2011 *)
    Table[Length[NestWhileList[If[EvenQ[#],#/2,3#+1]&,n,#!=1&]]-1,{n,80}] (* Harvey P. Dale, May 21 2012 *)
  • PARI
    a(n)=if(n<0,0,s=n; c=0; while(s>1,s=if(s%2,3*s+1,s/2); c++); c)
    
  • PARI
    step(n)=if(n%2,3*n+1,n/2);
    A006577(n)=if(n==1,0,A006577(step(n))+1); \\ Michael B. Porter, Jun 05 2010
    
  • 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, Jun 05 2017
    
  • Python
    def A006577(n):
        ct = 0
        while n != 1: n = A006370(n); ct += 1
        return ct # Ya-Ping Lu, Feb 22 2024
    
  • R
    collatz<-function(n) ifelse(n==1,0,1+ifelse(n%%2==0,collatz(n/2),collatz(3*n+1))); sapply(1:72, collatz) # Christian N. K. Anderson, Oct 09 2024

Formula

a(n) = A006666(n) + A006667(n).
a(n) = A112695(n) + 2 for n > 2. - Reinhard Zumkeller, Apr 18 2008
a(n) = A008908(n) - 1. - L. Edson Jeffery, Jul 21 2014
a(n) = A135282(n) + A208981(n) (after Alonso del Arte's comment in A208981), if 1 is reached, otherwise a(n) = -1. - Omar E. Pol, Apr 10 2022
a(n) = 2*A007814(n + 1) + a(A085062(n)) + 1 for n > 1. - Wing-Yin Tang, Jan 06 2025

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

A127886 Steps saved by choice in "3x+1" iteration.

Original entry on oeis.org

0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 88, 8, 0, 0, 75, 0, 8, 0, 0, 8, 8, 0, 8, 0, 88, 0, 8, 0, 0, 0, 75, 0, 8, 8, 0, 0, 0, 88, 88, 8, 8, 0, 8, 0, 0, 75, 75, 0, 8, 8, 0, 0, 0, 0, 75, 8
Offset: 1

Views

Author

David Applegate and N. J. A. Sloane, Feb 04 2007

Keywords

Comments

Normal "3x+1" iteration requires x->x/2 if x is even. a(n) is the number of iterations that can be saved by also allowing x->3x+1 if x is even.

Examples

			a(9) = 8 because for 9 the traditional 3x+1 iteration follows the 19-step path:
9 -> 28 -> 14 -> 7 -> 22 -> 11 -> 34 -> 17 -> 52 -> 26 -> 13 -> 40 -> 20 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1
while allowing x->3x+1 for even x gives the 11-step path:
9 -> 28 -> 85 -> 256 -> 128 -> 64 -> 32 -> 16 -> 8 -> 4 -> 2 -> 1
		

Crossrefs

Cf. A006577, A127885, A127887 (gives the indices of the nonzero entries).

Programs

  • Mathematica
    Table[Length@ NestWhileList[If[OddQ@ #, 3 # + 1, #/2] &, n, # > 1 &] - Length@ NestWhileList[Flatten[# /. {k_ /; OddQ@ k :> 3 k + 1, k_ /; EvenQ@ k :> {k/2, 3 k + 1}}] &, {n}, FreeQ[#, 1] &], {n, 126}] (* Michael De Vlieger, Aug 20 2017 *)

Formula

a(n) = A006577(n) - A127885(n).

A290100 Start from the singleton set S = {n}, and unless 1 is already a member of S, generate on each iteration a new set where each odd number k is replaced by 3k+1, and each even number k is replaced by 3k+1 and k/2. a(n) is the size of the set after the first iteration which has produced 1 as a member.

Original entry on oeis.org

1, 2, 12, 3, 8, 23, 381, 5, 73, 12, 187, 47, 39, 786, 537, 8, 109, 124, 2020, 23, 19, 381, 267, 81, 7768, 60, 6061, 73, 1238, 1128, 118945, 12, 1120, 187, 141, 234, 190, 3999, 18578, 39, 3394, 28, 2896, 747, 576, 537, 56496, 128, 533, 606, 9757, 109, 95, 12337, 8656, 118, 11306, 2020, 9309, 2309, 1789, 258213, 176262, 19
Offset: 1

Views

Author

Antti Karttunen, Aug 18 2017

Keywords

Comments

Records are {1, 2, 12, 23, 381, 786, 2020, 7768, 118945, 258213, 2124457, 40495936, 59752379, 65297014, 231177519} at positions {1, 2, 3, 6, 7, 14, 19, 25, 31, 62, 107, 127, 255, 295, 339}. - Michael De Vlieger, Aug 24 2017

Examples

			For n=1, the initial set from which we start is {1}, and it already contains 1, so a(1) = 1 as the size of that set is 1.
For n=2, the initial set is {2}, which will become set {1, 7} (because 2/2 = 1 and 3*2+1 = 7), and that set already contains 1, thus a(2) = 2.
For n=3, the initial set is {3}, the next set is 3*3+1 = {10}, from which we get {5, 31} -> {16, 94} -> {8, 47, 49, 283} -> {4, 25, 142, 148, 850} -> {2, 13, 71, 74, 76, 425, 427, 445, 2551} and from that one we get these 12 numbers: {1, 7, 37, 38, 40, 214, 223, 229, 1276, 1282, 1336, 7654}, and because 1 is among these, a(3) = 12.
For n = 12, the iteration proceeds as follows: {12} -> {6, 37} -> {3, 19, 112} -> {10, 56, 58, 337} -> {5, 28, 29, 31, 169, 175, 1012} -> {14, 16, 85, 88, 94, 506, 508, 526, 3037} -> {7, 8, 43, 44, 47, 49, 253, 254, 256, 263, 265, 283, 1519, 1525, 1579, 9112} -> {4, 22, 25, 127, 128, 130, 133, 142, 148, 760, 763, 769, 790, 796, 850, 4556, 4558, 4576, 4738, 27337} -> {2, 11, 13, 64, 65, 67, 71, 74, 76, 380, 382, 385, 391, 395, 398, 400, 425, 427, 445, 2278, 2279, 2281, 2288, 2290, 2308, 2369, 2371, 2389, 2551, 13669, 13675, 13729, 14215, 82012} -> {1, 7, 32, 34, 37, 38, 40, 190, 191, 193, 196, 199, 200, 202, 214, 223, 229, 1139, 1141, 1144, 1145, 1147, 1154, 1156, 1174, 1186, 1195, 1201, 1276, 1282, 1336, 6835, 6838, 6844, 6865, 6871, 6925, 7108, 7114, 7168, 7654, 41006, 41008, 41026, 41188, 42646, 246037}. As this last set contains 1 and has 47 members, a(12) = 47. Note how here in the 7th iteration the term 22 is a child of both 7 (as 3*7+1) and 44 (as 44/2), but as these are sets, not multisets, 22 occurs only once in {4, 22, 25, ...}.
		

Crossrefs

Cf. A127885 (gives the number of iterations needed until 1 is present).
Cf. also A290101, A290102.

Programs

  • Mathematica
    Table[Length@ Last@ NestWhileList[Union@ Flatten[# /. {k_ /; OddQ@ k :> 3 k + 1, k_ /; EvenQ@ k :> {k/2, 3 k + 1}}] &, {n}, FreeQ[#, 1] &], {n, 64}] (* Michael De Vlieger, Aug 20 2017 *)
  • PARI
    allocatemem(2^31);
    A290100(n) = { my(S); S=[n]; while( S[1]!=1, S = vecsort( concat(apply(x->3*x+1, S), apply(x->x\2, select(x->x%2==0, S) )), , 8); ); length(S); } \\ After Max Alekseyev's code for A127885
    for(n=1,126,write("b290100.txt", n, " ", A290100(n)));
    
  • Python
    from sympy import flatten
    def a(n):
        if n==1: return 1
        L=[n]
        while not 1 in L:
            L=sorted(list(set(flatten([[3*k + 1, k/2] if k%2==0 else 3*k + 1 for k in L]))))
        return len(L)
    for i in range(1, 101): print(a(i)) # Indranil Ghosh, Aug 31 2017

Formula

a(n) >= A290102(n).

A125731 a(n) = minimal number of steps to get from 1 to n, where a step is x -> 3x+1 if x is odd, or x -> either x/2 or 3x+1 if x is even. Set a(n) = -1 if n cannot be reached from 1.

Original entry on oeis.org

0, 2, -1, 1, 6, -1, 3, 8, -1, 5, 5, -1, 2, 15, -1, 7, 7, -1, 12, 4, -1, 4, 9, -1, 9, 9, -1, 14, 14, -1, 6, 19, -1, 6, 11, -1, 11, 11, -1, 3, 29, -1, 16, 16, -1, 8, 8, -1, 8, 21, -1, 8, 13, -1, 26, 13, -1, 13, 13, -1, 5, 31, -1, 18, 18, -1, 5, 23, -1, 10
Offset: 1

Views

Author

David Applegate and N. J. A. Sloane, Feb 02 2007

Keywords

Comments

In contrast to the "3x+1" problem, here you are free to choose either step if x is even.
Clearly a(3k) = -1 for all k; we conjecture that a(n) >= 0 otherwise.
See A127885 for the number of steps in the reverse direction, from n to 1.

Examples

			The initial values use these paths:
1 -> 4 -> 2 -> 7 -> 22 -> 11.
1 -> 4 -> 13 -> 40 -> 20 -> 10 -> 5 -> 16 -> 8.
1 -> 4 -> 13 -> 40 -> 20 -> 10 -> 5 -> 16 -> 49 -> 148 -> 74 -> 37 -> 12 -> 56 -> 28 -> 14.
		

Programs

  • Maple
    # Code from David Applegate: Be careful - the function takes an iteration limit and returns the limit if it wasn't able to determine the answer (that is, if A125731(n,lim) == lim, all you know is that the value is >= lim). To use it, do manual iteration on the limit.
    A125731 := proc(n,lim) local d,d2; options remember;
    if (n = 1) then return 0; end if;
    if (n mod 3 = 0) then return -1; end if;
    if (lim <= 0) then return 0; end if;
    if (n > (3 ** (lim+1) - 1)/2) then return lim; end if;
    if (n mod 9 = 4 or n mod 9 = 7) then
    d := A125731((n-1)/3,lim-1);
    d2 := A125731(2*n,d);
    if (d2 < d) then d := d2; end if;
    else
    d := A125731(2*n,lim-1);
    end if;
    return 1+d;
    end proc;

A261870 a(n) = minimal number of steps to get from n to 1, where a step is x -> 3x-1 if x is odd, or x -> either x/2 or 3x-1 if x is even.

Original entry on oeis.org

0, 1, 4, 2, 15, 5, 13, 3, 16, 11, 6, 6, 19, 14, 9, 4, 35, 17, 17, 12, 25, 7, 20, 7, 33, 15, 15, 15, 10, 10, 23, 5, 36, 36, 18, 18, 31, 18, 13, 13, 26, 26, 8, 8, 26, 21, 21, 8, 34, 34, 21, 16, 16, 16, 29, 16, 29, 11, 11, 11, 24, 24, 24, 6, 37, 37, 24, 19, 19, 19, 19, 19, 32, 32, 19, 19, 14, 14, 14, 14, 27, 27, 27, 27, 27, 9, 40, 9, 27, 27, 22, 22, 22, 22, 22, 9, 35, 35, 35, 22
Offset: 1

Views

Author

Max Alekseyev, Sep 03 2015

Keywords

Comments

The 3x-1 variation of Collatz conjecture would imply that this sequence is well defined. In turn, if this sequence is well-defined, then A109732 represents a permutation of the odd positive integers.

Crossrefs

Programs

  • C
    /* See links. */
  • PARI
    { A261870(n) = my(S, k); S=[n]; k=0; while( S[1]!=1, k++; S=vecsort( concat(apply(x->3*x-1, S), apply(x->x\2, select(x->x%2==0, S) )), , 8);  ); k } /* Max Alekseyev, Sep 03 2015 */
    

A127887 Indices of nonzero terms of A127886.

Original entry on oeis.org

9, 18, 27, 28, 31, 33, 36, 37, 39, 41, 43, 47, 49, 50, 54, 55, 56, 57, 59, 62, 63, 65, 66, 71, 72, 73, 74, 78, 79, 82, 83, 86, 87, 89, 91, 94, 95, 97, 98, 99, 100, 103, 105, 107, 108, 109, 110, 111, 112, 114, 115, 118, 119, 121, 123, 124, 125, 126, 129, 130, 131, 132, 133, 134, 135, 137, 139, 142, 143, 144, 145
Offset: 1

Views

Author

David Applegate and N. J. A. Sloane, Feb 04 2007

Keywords

Comments

These are the numbers for which allowing the choice of x/2 or 3x+1 in the "3x+1" iteration makes a difference in the minimal number of steps to reach 1.
Thus these are the n for which A006577(n) > A127885(n).

Crossrefs

Programs

  • Mathematica
    Position[#, k_ /; k > 0][[All, 1]] &@ Table[Length@ NestWhileList[If[OddQ@ #, 3 # + 1, #/2] &, n, # > 1 &] - Length@ NestWhileList[Flatten[# /. {k_ /; OddQ@ k :> 3 k + 1, k_ /; EvenQ@ k :> {k/2, 3 k + 1}}] &, {n}, FreeQ[#, 1] &], {n, 126}] (* Michael De Vlieger, Aug 20 2017 *)

Extensions

More terms from Antti Karttunen, Aug 18 2017
Showing 1-10 of 13 results. Next