30 lines
672 B
Text
30 lines
672 B
Text
local bigint = require "pluto:bigint"
|
|
local fmt = require "fmt"
|
|
require "table2"
|
|
|
|
local function fib1000()
|
|
local a = bigint.new(0)
|
|
local b = bigint.new(1)
|
|
local r = table.create(1000)
|
|
for i = 1, 1000 do
|
|
r[i] = b
|
|
a, b = b, b + a
|
|
end
|
|
return r
|
|
end
|
|
|
|
local function show(c, title)
|
|
local f = table.rep(9, 0)
|
|
for c as v do
|
|
local t = v:tostring():byte() - 48
|
|
f[t] += 1
|
|
end
|
|
print(title)
|
|
print("Digit Observed Predicted")
|
|
for i = 1, #f do
|
|
local t = math.log(1 / i + 1, 10)
|
|
fmt.print(" %d %8.3f %8.3f", i, f[i] / #c, t)
|
|
end
|
|
end
|
|
|
|
show(fib1000(), "First 1000 Fibonacci numbers:")
|