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

A056792 Minimal number of steps to get from 0 to n by (a) adding 1 or (b) multiplying by 2.

Original entry on oeis.org

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

Views

Author

N. J. A. Sloane, Sep 01 2000

Keywords

Comments

A stopping problem: begin with n and at each stage if even divide by 2 or if odd subtract 1. That is, iterate A029578 while nonzero.
From Peter Kagey, Jul 16 2015: (Start)
The number of appearances of n in this sequence is identically A000045(n). Proof:
By application of the formula,
"a(0) = 0, a(2*n+1) = a(2*n) + 1 and a(2*n) = a(n) + 1",
it can be seen that:
{i: a(i) = n} = {2*i: a(i) = n-1, n>0} U {2*i+1: a(i) = n-2, n>1}.
Because the two sets on the left hand side share no elements:
|{i: a(i) = n}| = |{i: a(i) = n-1, n>0}| + |{i: a(i) = n-2, n>1}|
Notice that
|{i : a(i) = 1}| = |{1}| = 1 = A000045(1) and
|{i : a(i) = 2}| = |{2}| = 1 = A000045(2).
Therefore the number of appearances of n in this sequence is A000045(n). (End)

Examples

			12 = 1100 in binary, so a(12)=2+4-1=5.
		

Crossrefs

Equals A056791 - 1. The least inverse (indices of record values) of A056792 is A052955 prepended with 0. See also A014701, A115954, A056796, A056817.
Cf. A000120, A070939, A007088: base 2 sequences.
Analogous sequences with a different multiplier k: A061282 (k=3), A260112 (k=4).

Programs

  • Haskell
    c i = if i `mod` 2 == 0 then i `div` 2 else i - 1
    b 0 foldCount = foldCount
    b sheetCount foldCount = b (c sheetCount) (foldCount + 1)
    a056792 n = b n 0 -- Peter Kagey, Sep 02 2015
  • Maple
    a:= n-> (l-> nops(l)+add(i, i=l)-1)(convert(n, base, 2)):
    seq(a(n), n=0..105);  # Alois P. Heinz, Jul 16 2015
  • Mathematica
    f[ n_Integer ] := (c = 0; k = n; While[ k != 0, If[ EvenQ[ k ], k /= 2, k-- ]; c++ ]; c); Table[ f[ n ], {n, 0, 100} ]
    f[n_] := Floor@ Log2@ n + DigitCount[n, 2, 1]; Array[f, 100] (* Robert G. Wilson v, Jul 31 2012 *)
  • PARI
    a(n)=if(n<1,0,n-valuation(n!*sum(i=1,n,1/i),2))
    
  • PARI
    a(n)=if(n<1,0,1+a(if(n%2,n-1,n/2)))
    
  • PARI
    a(n)=if(n<1,0,n=binary(n);sum(i=1,#n,n[i])+#n-1) \\ Charles R Greathouse IV, Apr 11 2012
    

Formula

a(0) = 0, a(2*n+1) = a(2*n) + 1 and a(2*n) = a(n) + 1.
a(n) = n-valuation(A000254(n), 2) for n>0. - Benoit Cloitre, Mar 09 2004
a(n) = A000120(n) + A070939(n) - 1. - Michel Marcus, Jul 17 2015
a(n) = (weight of binary expansion of n) + (length of binary expansion of n) - 1.

Extensions

More terms from James Sellers, Sep 06 2000
More terms from David W. Wilson, Sep 07 2000

A260112 Minimal number of steps to get from 0 to n by (a) adding 1 or (b) multiplying by 4.

Original entry on oeis.org

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

Views

Author

Peter Kagey, Jul 16 2015

Keywords

Comments

a(n) = (Weight of quaternary expansion of n) + (length of quaternary expansion of n) - 1.

Examples

			For a(308) = 9, the nine steps are: 308 => 77 => 76 => 19 => 18 => 17 => 16 => 4 => 1 => 0.
		

Crossrefs

Analogous sequences with a different multiplier k: A056792 (k=2), A061282 (k=3).
Cf. A053737, A110591, A007090: base 4 sequences.

Programs

  • Haskell
    c i = if i `mod` 4 == 0 then i `div` 4 else i - 1
    b 0 foldCount = foldCount
    b sheetCount foldCount = b (c sheetCount) (foldCount + 1)
    a260112 n = b n 0 -- Peter Kagey, Sep 02 2015
  • Maple
    a:= n-> (l-> nops(l)+add(i, i=l)-1)(convert(n, base, 4)):
    seq(a(n), n=0..105);  # Alois P. Heinz, Jul 16 2015
  • PARI
    a(n)=sumdigits(n,4)+#digits(n,4)-1 \\ Charles R Greathouse IV, Jul 16 2015
    
  • Ruby
    def a(n); n.to_s(4).length + n.to_s(4).split('').map(&:to_i).reduce(:+) - 1 end
    

Formula

a(n) = A053737(n) + A110591(n) - 1. - Michel Marcus, Jul 17 2015

A297025 Number of iterations of A220096 required to reach 0 starting from n.

Original entry on oeis.org

0, 1, 2, 3, 3, 4, 4, 5, 4, 4, 5, 6, 5, 6, 6, 5, 5, 6, 5, 6, 6, 6, 7, 8, 6, 5, 7, 5, 7, 8, 6, 7, 6, 7, 7, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 6, 9, 10, 7, 6, 6, 7, 8, 9, 6, 7, 8, 7, 9, 10, 7, 8, 8, 7, 7, 7, 8, 9, 8, 9, 7, 8, 7, 8, 8, 6, 8, 7, 8, 9, 8, 6, 9, 10, 8, 7
Offset: 0

Views

Author

Peter Kagey and Alec Jones, Dec 24 2017

Keywords

Comments

Records occur at indices 0, 1, 2, 3, 5, 7, 11, 22, 23, 46, 47, 94, ... (see A297026).

Examples

			For n = 14, a(14) = 6 because six iterations are required to reach zero:
A220096(14) = 7,
A220096(7)  = 6,
A220096(6)  = 3,
A220096(3)  = 2,
A220096(2)  = 1, and
A220096(1)  = 0.
		

Crossrefs

Cf. A220096. Positions of records at A297026.

Programs

  • Mathematica
    g[n_Integer] := If[n == 1, 0, Block[{fi = FactorInteger@ n}, If[Plus @@ (Last@# & /@ FactorInteger@n) == 1, n -1, n/fi[[1, 1]] ]]]; f[n_] := Length@ NestWhileList[g, n, # > 0 &] -1; Array[f, 86, 0] (* Robert G. Wilson v, Dec 24 2017 *)
  • PARI
    f(n) = if (n==1, 0, isprime(n), n-1, my(d=divisors(n)); d[#d-1]);
    a(n) = my(nb = 0); while (n, n = f(n); nb++); nb; \\ Michel Marcus, Dec 24 2017
Showing 1-3 of 3 results.