Math::Zeckendorf
Given an Int, generate the Zeckendorf decomposition of that number,
or the Dual Zeckendorf decomposition.
Return either the zeckendorf or the dual-zeckendorf decomposition. If
:numbers is enabled, instead return the corresponding Fibonnaci numbers.
use Math::Zeckendorf;
say zeckendorf(27);
# OUTPUT: «[1 0 0 1 0 0 1]»
say zeckendorf(27, :numbers);
# OUTPUT: «[21 5 1]»
say dual-zeckendorf(27);
# OUTPUT: «[1 1 0 1 1 1]»
say dual-zeckendorf(27, :numbers);
# OUTPUT: «[13 8 3 2 1]»Inspired by the "Base Fibonacci" Numberphile video.
The binary digits returned from zeckendorf do not include any sequential Fibonacci numbers.
See https://oeis.org/A014417
Conversely, the binary digits returned from dual-zeckendorf do not contain any gaps of Fibonacci numbers
greater than size 1.
See https://oeis.org/A104326
See also Zeckendorf's theorem on wikipedia.
Will Coleda will@coleda.com
Copyright 2026 Will Coleda
This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.