34 lines
676 B
Text
34 lines
676 B
Text
global counts, total
|
|
|
|
procedure main()
|
|
|
|
counts := table(0)
|
|
total := 0.0
|
|
every benlaw(fib(1 to 1000))
|
|
|
|
every i := 1 to 9 do
|
|
write(i,": ",right(100*counts[string(i)]/total,9)," ",100*P(i))
|
|
|
|
end
|
|
|
|
procedure benlaw(n)
|
|
if counts[n ? (tab(upto('123456789')),move(1))] +:= 1 then total +:= 1
|
|
end
|
|
|
|
procedure P(d)
|
|
return log(1+1.0/d, 10)
|
|
end
|
|
|
|
procedure fib(n) # From Fibonacci Sequence task
|
|
return fibMat(n)[1]
|
|
end
|
|
|
|
procedure fibMat(n)
|
|
if n <= 0 then return [0,0]
|
|
if n = 1 then return [1,0]
|
|
fp := fibMat(n/2)
|
|
c := fp[1]*fp[1] + fp[2]*fp[2]
|
|
d := fp[1]*(fp[1]+2*fp[2])
|
|
if n%2 = 1 then return [c+d, d]
|
|
else return [d, c]
|
|
end
|