Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
43
Task/Fusc-sequence/Lua/fusc-sequence.lua
Normal file
43
Task/Fusc-sequence/Lua/fusc-sequence.lua
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
function fusc(n)
|
||||
n = math.floor(n)
|
||||
if n == 0 or n == 1 then
|
||||
return n
|
||||
elseif n % 2 == 0 then
|
||||
return fusc(n / 2)
|
||||
else
|
||||
return fusc((n - 1) / 2) + fusc((n + 1) / 2)
|
||||
end
|
||||
end
|
||||
|
||||
function numLen(n)
|
||||
local sum = 1
|
||||
while n > 9 do
|
||||
n = math.floor(n / 10)
|
||||
sum = sum + 1
|
||||
end
|
||||
return sum
|
||||
end
|
||||
|
||||
function printLargeFuscs(limit)
|
||||
print("Printing all largest Fusc numbers up to " .. limit)
|
||||
print("Index-------Value")
|
||||
local maxLen = 1
|
||||
for i=0,limit do
|
||||
local f = fusc(i)
|
||||
local le = numLen(f)
|
||||
if le > maxLen then
|
||||
maxLen = le
|
||||
print(string.format("%5d%12d", i, f))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function main()
|
||||
print("Index-------Value")
|
||||
for i=0,60 do
|
||||
print(string.format("%5d%12d", i, fusc(i)))
|
||||
end
|
||||
printLargeFuscs(math.pow(2, 31) - 1)
|
||||
end
|
||||
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue