1, 2, 4, 8, 1, 3, 6, 1 ... is a non-cyclic series where a(n) represents the leading digit of 2^n.
a) How many ones are there within the first 3000 members?
b) Same question for a digit d, other than digit one.
DEFDBL A-Z
log10 = LOG(10)
log2 = LOG(2) / LOG(10)
FOR n = 1 TO 3000
l = n * log2
l = l - INT(l)
p = INT(10 ^ l + 9.999999999999999D-12)
ct(p) = ct(p) + 1
NEXT
FOR i = 1 TO 9
PRINT i, ct(i), ct(i) / 3000
NEXT
finds
n number fraction of the numbers
1 903 .301
2 529 .1763333333333333
3 374 .1246666666666667
4 291 .097
5 238 7.933333333333334D-02
6 201 .067
7 173 5.766666666666666D-02
8 155 5.166666666666667D-02
9 136 4.533333333333334D-02
The fudge factor added by
p = INT(10 ^ l + 9.999999999999999D-12)
was necessary as it was misreporting 8 itself as 7 due to rounding error that made 2^3 come out as something like 7.999999999999.
5 dim Ct(9)
10 for N=1 to 3000
20 S=cutspc(str(2^N))
30 Ct(val(left(S,1)))=Ct(val(left(S,1)))+1
40 next
50 for I=1 to 9:print I,Ct(I),Ct(I)/3000,tab(40),(log(I+1)-log(I))/log(10):next
finds
n number fraction expected fraction
1 903 0.301 0.3010299956639811951
2 529 0.1763333333333333332 0.1760912590556812419
3 374 0.1246666666666666666 0.1249387366082999532
4 291 0.097 0.0969100130080564141
5 238 0.0793333333333333332 0.0791812460476248277
6 201 0.067 0.066946789630613198
7 173 0.0576666666666666666 0.0579919469776867551
8 155 0.0516666666666666666 0.0511525224473812888
9 136 0.0453333333333333332 0.0457574905606751253
The expected fraction column is that based on the logs of the digits as per Benford's law.
|
Posted by Charlie
on 2011-02-18 18:39:55 |