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.

A070975 Number of steps to reach 1 in `3x+1' (or Collatz) problem starting with prime(n).

Original entry on oeis.org

1, 7, 5, 16, 14, 9, 12, 20, 15, 18, 106, 21, 109, 29, 104, 11, 32, 19, 27, 102, 115, 35, 110, 30, 118, 25, 87, 100, 113, 12, 46, 28, 90, 41, 23, 15, 36, 23, 67, 31, 31, 18, 44, 119, 26, 119, 39, 70, 13, 34, 83, 52, 21, 65, 122, 78, 29, 42, 16, 42, 60, 117, 37, 86, 130, 37, 24
Offset: 1

Views

Author

Benoit Cloitre, May 17 2002

Keywords

Crossrefs

Cf. A006577.

Programs

  • Mathematica
    ns[n_]:=Length[NestWhileList[If[EvenQ[#],#/2,3#+1]&,n,#!=1&]]-1; ns/@ Prime[Range[70]] (* Harvey P. Dale, Jul 29 2014 *)
  • PARI
    for(n=2,100,s=prime(n); t=0; while(s!=1,t++; if(s%2==0,s=s/2,s=3*s+1); if(s==1,print1(t,","); ); ))
    
  • Python
    from sympy import prime
    def a006577(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
    def a(n): return a006577(prime(n))
    print([a(n) for n in range(1, 101)]) # Indranil Ghosh, Jun 05 2017

Formula

a(n) = A006577(prime(n)). - Michel Marcus, Sep 07 2014