RosettaCodeData/Task/Zeckendorf-number-representation/MiniScript/zeckendorf-number-representation.mini
2023-12-16 21:33:55 -08:00

27 lines
430 B
Text

fibonacci = function(val)
if val < 1 then return []
fib = []
a = 1; b = 2
while a <= val
fib.insert(0, a)
next = a + b
a = b
b = next
end while
return fib
end function
zeckendorf = function(val)
seq = fibonacci(val)
s = ""
for i in seq
onOff = val >= i and (s == "" or s[-1] == "0")
s += str(onOff)
val -= (i*onOff)
end for
return s
end function
for i in range(1, 20)
print [i, zeckendorf(i)]
end for