diff --git a/sources/projects/zeckendorf/description.md b/sources/projects/zeckendorf/description.md new file mode 100644 index 000000000..e02bab55e --- /dev/null +++ b/sources/projects/zeckendorf/description.md @@ -0,0 +1,62 @@ +[Edouard Zeckendorf][3] was a Belgian amateur mathematician who proposed a +[Theorem][1] that states that every non-negative integer (_N_) can be +represented as a sum of distinct non-consecutive [Fibonacci Numbers][2]. In +other words, + +* _N_ = _F__c_1 + _F__c_2 + ... + _F__c__n_ + +where: + +* _F__k_ is the _k_ th Fibonacci number +* _c__i_ ≥ 2 +* _c__i_ + 1 > _c__i_ + 1 + +Each Fibonacci number (_F__k_) is the sum of the previous two Fibonacci +numbers: + +* _F_0 = 0 +* _F_1 = 1 +* _F_2 = _F_1 + _F_0 = 0 + 1 = 1 +* _F_3 = _F_2 + _F_1 = 1 + 1 = 2 +* ... +* _F__k_ = _F__k_ - 1 + _F__k_ - 2 + +This relationship is the reason why non-consecutive Fibonacci numbers are used. + +To find the Fibonacci numbers that add up to _N_: + +* Find all the Fibonacci numbers up to and including _N_, starting at + _F_2. +* Going from largest to smallest, select each Fibonacci number such that the + sum of this value plus all the prior selected values is less than or equal to + _N_. + +For example, for _N_ = 67, these are the Fibonacci numbers up to 67: + +* 1, 2, 3, 5, 8, 13, 21, 34, 55 + +Select the appropriate Fibonacci numbers: + +| Trial Sum | Fibonacci Number | Selected | +| :---------: | :--------------: | :------: | +| 0 | 55 | ✅ | +| 55 | 34 | | +| 55 | 21 | | +| 55 | 13 | | +| 55 | 8 | ✅ | +| 63 | 5 | | +| 63 | 3 | ✅ | +| 66 | 2 | | +| 66 | 1 | ✅ | + +Therefore, using the selected numbers, _N_ can be represented as: + +* 67 = 55 + 8 + 3 + 1 + +A possible optimization for this procedure would be to skip Fibonacci +numbers that are consecutive to the last selected value and to terminate +the loop as soon as the sum equals to _N_. + +[1]: https://en.wikipedia.org/wiki/Zeckendorf%27s_theorem +[2]: https://en.wikipedia.org/wiki/Fibonacci_sequence +[3]: https://en.wikipedia.org/wiki/Edouard_Zeckendorf diff --git a/sources/projects/zeckendorf/featured-image.png b/sources/projects/zeckendorf/featured-image.png new file mode 100755 index 000000000..5357e0e94 Binary files /dev/null and b/sources/projects/zeckendorf/featured-image.png differ diff --git a/sources/projects/zeckendorf/requirements.md b/sources/projects/zeckendorf/requirements.md new file mode 100644 index 000000000..b872dfef2 --- /dev/null +++ b/sources/projects/zeckendorf/requirements.md @@ -0,0 +1,8 @@ +Create a file called "Zeckendorf" using the naming convention appropriate for +your language of choice. + +Write a sample program that accepts a single non-negative integer from the +command line and outputs a comma-separated list of Fibonacci numbers whose +sum equals the specified value. For zero, output an empty list. If the command +line argument is missing or not a non-negative integer, output the error +message specified in the [Testing](#testing) section.