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-5 of 5 results.

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

A060412 In the '3x+1' problem, these values for the starting value set new records for the "dropping time", number of steps to reach a lower value than the start.

Original entry on oeis.org

2, 3, 7, 27, 703, 10087, 35655, 270271, 362343, 381727, 626331, 1027431, 1126015, 8088063, 13421671, 20638335, 26716671, 56924955, 63728127, 217740015, 1200991791, 1827397567, 2788008987, 12235060455
Offset: 1

Views

Author

N. J. A. Sloane, Apr 06 2001; b-file added Nov 27 2007

Keywords

Comments

The (3x+1)/2 steps and the halving steps are counted. - Don Reble, May 13 2006
Where records occur in A102419 (could be prefixed by an initial 1). - N. J. A. Sloane, Oct 20 2012

Examples

			See A102419.
		

Crossrefs

A060413 gives associated "dropping times", A060414 the maximal values and A060415 the steps at which the maxima occur. See also A217934.

Programs

  • Mathematica
    dcoll[n_]:=Length[NestWhileList[If[EvenQ[#],#/2,3#+1]&,n,#>=n&]]; t={max=2}; Do[If[(y=dcoll[n])>max,max=y; AppendTo[t,n]],{n,3,1130000,4}]; t (* Jayanta Basu, May 28 2013 *)

A008884 3x+1 sequence starting at 27.

Original entry on oeis.org

27, 82, 41, 124, 62, 31, 94, 47, 142, 71, 214, 107, 322, 161, 484, 242, 121, 364, 182, 91, 274, 137, 412, 206, 103, 310, 155, 466, 233, 700, 350, 175, 526, 263, 790, 395, 1186, 593, 1780, 890, 445, 1336, 668, 334, 167, 502, 251, 754, 377, 1132, 566, 283, 850, 425, 1276, 638, 319, 958, 479, 1438, 719, 2158, 1079
Offset: 0

Views

Author

Keywords

Comments

27=A060412(4); a(A006577(27))=a(111)=1; a(n)=A161021(n+59) for n with 103<=n<=111. - Reinhard Zumkeller, Jun 03 2009
At step 109 enters the loop 4 2 1 4 2 1 4 2 1 ... - N. J. A. Sloane, Jul 27 2019

References

  • R. K. Guy, Unsolved Problems in Number Theory, E16.
  • H.-O. Peitgen et al., Chaos and Fractals, Springer, p. 33.

Crossrefs

Row 27 of A347270.

Programs

  • Magma
    [ n eq 1 select 27 else IsOdd(Self(n-1)) select 3*Self(n-1)+1 else Self(n-1) div 2: n in [1..70] ]; // Klaus Brockhaus, Dec 25 2010
    
  • Maple
    f := proc(n) option remember; if n = 0 then 27; elif f(n-1) mod 2 = 0 then f(n-1)/2 else 3*f(n-1)+1; fi; end;
  • Mathematica
    NestList[If[EvenQ[#],#/2,3#+1]&,27,70] (* Harvey P. Dale, Jun 30 2011 *)
  • PARI
    Collatz(n,lim=0)={
    my(c=n,e=0,L=List(n)); if(lim==0, e=1; lim=n*10^6);
    for(i=1,lim, if(c%2==0, c=c/2, c=3*c+1); listput(L,c); if(e&&c==1, break));
    return(Vec(L)); }
    print(Collatz(27)) \\ A008884 (from 27 to the first 1)
    \\ Anatoly E. Voevudko, Mar 26 2016

Formula

a(0) = 27, a(n) = 3*a(n-1)+1 if a(n-1) is odd, a(n) = a(n-1)/2 if a(n-1) is even. - Vincenzo Librandi, Dec 24 2010; corrected by Klaus Brockhaus, Dec 25 2010

Extensions

More terms from Larry Reeves (larryr(AT)acm.org), Apr 27 2001

A161021 Collatz (or 3x+1) trajectory starting at 703.

Original entry on oeis.org

703, 2110, 1055, 3166, 1583, 4750, 2375, 7126, 3563, 10690, 5345, 16036, 8018, 4009, 12028, 6014, 3007, 9022, 4511, 13534, 6767, 20302, 10151, 30454, 15227, 45682, 22841, 68524, 34262, 17131, 51394, 25697, 77092, 38546, 19273, 57820, 28910
Offset: 0

Views

Author

Reinhard Zumkeller, Jun 03 2009

Keywords

Comments

703 = A060412(5); a(A006577(703)) = a(170) = 1;
a(n) = A008884(n-59) for n with 162 <= n <= 170;
a(n) = A161022(n+53) for n with 155 <= n <= 170;
a(n) = A161023(n+153) for n with 144 <= n <= 170.

Programs

  • Mathematica
    NestList[If[EvenQ[#],#/2,3#+1]&,703,40] (* Harvey P. Dale, Nov 27 2011 *)

Extensions

Edited by N. J. A. Sloane, Jul 27 2019

A161023 Collatz trajectory starting at 35655.

Original entry on oeis.org

35655, 106966, 53483, 160450, 80225, 240676, 120338, 60169, 180508, 90254, 45127, 135382, 67691, 203074, 101537, 304612, 152306, 76153, 228460, 114230, 57115, 171346, 85673, 257020, 128510, 64255, 192766, 96383, 289150, 144575, 433726
Offset: 0

Views

Author

Reinhard Zumkeller, Jun 03 2009

Keywords

Comments

35655 = A060412(7); a(A006577(35655)) = a(323) = 1.
a(n) = A161021(n-153) for n with 297 <= n <= 323;
a(n) = A161022(n-100) for n with 308 <= n <= 323.
At step 321 becomes periodic: 4 2 1 4 2 1 4 2 1 ... - N. J. A. Sloane, Jul 27 2019

Crossrefs

Cf. A008884.

Programs

  • Mathematica
    NestWhileList[If[EvenQ[#],#/2,3#+1]&,35655,#>1&] (* Harvey P. Dale, Apr 28 2016 *)

Extensions

Edited by N. J. A. Sloane, Jul 27 2019
Showing 1-5 of 5 results.