OFFSET
0,3
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(2n+1) = a(2n) + 1 and a(2n) = 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)
LINKS
Charles R Greathouse IV, Table of n, a(n) for n = 0..10000
Hugo Pfoertner, Addition chains
FORMULA
a(0) = 0, a(2n+1) = a(2n) + 1 and a(2n) = a(n) + 1.
a(n) = n-valuation(A000254(n), 2) for n>0. - Benoit Cloitre, Mar 09 2004
a(n) = (weight of binary expansion of n) + (length of binary expansion of n) - 1.
EXAMPLE
12 = 1100 in binary, so a(12)=2+4-1=5.
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 *)
PROG
(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)=n=binary(n); sum(i=1, #n, n[i])+#n-1 \\ Charles R Greathouse IV, Apr 11 2012
(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
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
N. J. A. Sloane, Sep 01 2000
EXTENSIONS
More terms from James A. Sellers, Sep 06 2000
More terms from David W. Wilson, Sep 07 2000
STATUS
approved