Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions sources/projects/zeckendorf/description.md
Original file line number Diff line number Diff line change
@@ -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_<sub>_c_<sub>1</sub></sub> + _F_<sub>_c_<sub>2</sub></sub> + ... + _F_<sub>_c_<sub>_n_</sub></sub>

where:

* _F_<sub>_k_</sub> is the _k_ th Fibonacci number
* _c_<sub>_i_</sub> &ge; 2
* _c_<sub>_i_ + 1</sub> &gt; _c_<sub>_i_</sub> + 1

Each Fibonacci number (_F_<sub>_k_</sub>) is the sum of the previous two Fibonacci
numbers:

* _F_<sub>0</sub> = 0
* _F_<sub>1</sub> = 1
* _F_<sub>2</sub> = _F_<sub>1</sub> + _F_<sub>0</sub> = 0 + 1 = 1
* _F_<sub>3</sub> = _F_<sub>2</sub> + _F_<sub>1</sub> = 1 + 1 = 2
* ...
* _F_<sub>_k_</sub> = _F_<sub>_k_ - 1</sub> + _F_<sub>_k_ - 2</sub>

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_<sub>2</sub>.
* 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 | &#9989; |
| 55 | 34 | |
| 55 | 21 | |
| 55 | 13 | |
| 55 | 8 | &#9989; |
| 63 | 5 | |
| 63 | 3 | &#9989; |
| 66 | 2 | |
| 66 | 1 | &#9989; |

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
Binary file added sources/projects/zeckendorf/featured-image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions sources/projects/zeckendorf/requirements.md
Original file line number Diff line number Diff line change
@@ -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.
Loading