All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars
 perplexus dot info

 a) is easy, b) is not (Posted on 2011-02-18)
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.

Comments: ( Back to comment list | You must be logged in to post comments.)
 2 computer ways | Comment 5 of 8 |

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

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 fraction1       903     0.301                           0.30102999566398119512       529     0.1763333333333333332           0.17609125905568124193       374     0.1246666666666666666           0.12493873660829995324       291     0.097                           0.09691001300805641415       238     0.0793333333333333332           0.07918124604762482776       201     0.067                           0.0669467896306131987       173     0.0576666666666666666           0.05799194697768675518       155     0.0516666666666666666           0.05115252244738128889       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

 Search: Search body:
Forums (0)