Digit Count

Author

Eric W. Weisstein
July 27, 2008

This notebook downloaded from http://mathworld.wolfram.com/notebooks/Numbers/DigitCount.nb.

For more information, see Eric's MathWorld entry http://mathworld.wolfram.com/DigitCount.html.

©2008 Wolfram Research, Inc. except for portions noted otherwise

Table of counts in base 10

None of these are in Sloane

Transpose[Table[DigitCount[n,10],{n,100}]]//ColumnForm

Number of ones

a[n_]:=a[n/2]/;EvenQ[n]
a[n_]:=a[(n-1)/2]+1/;OddQ[n]
a[0]:=0

b[n_]:=2n-Log[2,Denominator[1/n! Derivative[n][(1-#)^(-1/2)&][0]]]

c[n_]:=n-IntegerExponent[n!,2]

Table[{n,BaseForm[n,2],DigitCount[n,2,1],a[n],b[n],c[n]},{n,20}]//TableForm

Plot of 1's

<<Utilities`Plot`

Show[GraphicsArray[IntegerListPlot[Table[DigitCount[n,2,1],{n,#}],DisplayFunction->Identity,
AxesLabel->TraditionalForm/@{n,(Subscript[N, 1])[n]}]&/@{100,2000}]]

Formula

Table[Denominator[(1/(n!))Derivative[n][(((1-#))^(-1/2))&][0]],{n,0,10}]

Table[2n-Log[2,Denominator[(1/(n!))Derivative[n][(((1-#))^(-1/2))&][0]]],{n,0,20}]

Sum

n-Sum[Floor[(n/(2^k))],{k,Floor[Log[2,n]]}]

Recurrence

a[n_]:=a[n/2]/;EvenQ[n]
a[n_]:=a[(n-1)/2]+1/;OddQ[n]
a[0]:=0

Table[a[n],{n,0,20}]

V6

RSolve[{a[2n]==a[n],a[2n+1]==a[n]+1,a[0]==0},a[n],n]

RSolve[{a[n]==If[EvenQ[n],a[n/2],a[(n-1)/2]+1],a[0]==0},a[n],n]

V7

RSolve[{a[2n]==a[n],a[2n+1]==a[n]+1,a[0]==0},a[n],n]

RSolve[{a[n]==If[EvenQ[n],a[n/2],a[(n-1)/2]+1],a[0]==0},a[n],n]

...wrong for odd n...

Table[((Log[1+n])/(Log[2])),{n,0,10}]//FullSimplify

RSolve[{a[n]==If[OddQ[n],a[(n-1)/2]+1,a[n/2]],a[0]==0},a[n],n]

Sondow's Sums

(∑_n^∞)((DigitCount[n,2,0]+DigitCount[n,2,1])/(2 n (2 n+1)))==ℽ

V6

Sum[((DigitCount[n,2,1]+DigitCount[n,2,0])/(2n(2n+1))),{n,∞}]

Plus@@N[Table[((Plus@@DigitCount[n,2])/(2n(2n+1))),{n,10^5}]]//Timing

EulerGamma//N

V7

Sum[((DigitCount[n,2,1]+DigitCount[n,2,0])/(2n(2n+1))),{n,∞}]

Sum[((DigitCount[n,2,1]+DigitCount[n,2,0])/(2n(2n+1))),{n,10^5}]//N//Timing

(∑_n^∞)((DigitCount[n,2,1]-DigitCount[n,2,0])/(2 n (2 n+1)))==ln((4/π))

V6

Plus@@N[Table[((Subtract@@DigitCount[n,2])/(2n(2n+1))),{n,10^5}]]//Timing

Log[4/π]//N

V7

Sum[((DigitCount[n,2,1]-DigitCount[n,2,0])/(2n(2n+1))),{n,∞}]

Sum[((DigitCount[n,2,1]-DigitCount[n,2,0])/(2n(2n+1))),{n,10^5}]//N//Timing

Numbers of Even and Odd Digits

N[Sum[Count[IntegerDigits[2^n],_?OddQ]/2^n,{n,200}],50]//Timing

N[Sum[Count[IntegerDigits[2^n],_?EvenQ]/2^n,{n,500}],50]//Timing

V6

Sum[((Floor[n Log[10,2]]+1)/(2^n)),{n,∞}]

N[Sum[((Floor[n Log[10,2]]+1)/(2^n)),{n,100}]-(1/9),50]

V7

Sum[((Floor[n Log[10,2]]+1)/(2^n)),{n,∞}]