27 lines
828 B
Text
27 lines
828 B
Text
local fmt = require "fmt"
|
|
|
|
print("The first 61 numbers in the fusc sequence are:")
|
|
local fusc = {0, 1}
|
|
local fusc2 = {{0, 0}}
|
|
local max_len = 1
|
|
local n = 2
|
|
while n < 20e6 do -- limit to indices under 20 million say
|
|
local f = (n % 2 == 0) ? fusc[n/2 + 1] : fusc[(n - 1)/2 + 1] + fusc[(n+1)/2 + 1]
|
|
fusc:insert(f)
|
|
local len = #tostring(f)
|
|
if len > max_len then
|
|
max_len = len
|
|
if n <= 60 then
|
|
fusc2:insert({n, f})
|
|
else
|
|
fmt.print("%10s %s", fmt.int(n), fmt.int(f))
|
|
end
|
|
end
|
|
if n == 60 then
|
|
for fusc as e do io.write($"{e} ") end
|
|
print("\n\nFirst terms longer than any previous ones for indices < 20,000,000:")
|
|
print(" Index Value")
|
|
for fusc2 as iv do fmt.print("%10d %d", iv[1], iv[2]) end
|
|
end
|
|
n += 1
|
|
end
|