Leonardo number: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | 1 | # Leonardo number | |
| 2 | 2 | ||
| 3 | 3 | The Leonardo Sequence is the series of numbers: | |
| 4 | 4 | ||
| 5 | - | ||
| 5 | + | ```text | |
| 6 | + | 1, 1, 3, 5, 9, 15, 25 ... | |
| 7 | + | ``` | |
| 6 | 8 | ||
| 7 | 9 | ## Recursive way | |
| 8 | 10 | ||
| 9 | 11 | ``` pascal | |
| 10 | 12 | function LeonardoNumber( n : integer ):integer; | |
| 11 | 13 | begin | |
| 12 | 14 | if n > 1 then result := LeonardoNumber( n - 1 ) + LeonardoNumber( n - 2 ) + 1 | |
| 13 | 15 | else result := 1; | |
| 14 | 16 | end; | |
| 15 | 17 | ``` | |
| 16 | 18 | ||
| 17 | 19 | ## Making use of [[Fibonacci number|Fibonacci numbers]] | |
| 18 | 20 | ||
| 19 | 21 | ``` pascal | |
| 20 | 22 | function LeonardoNumber2( n : integer ):integer; | |
| 21 | 23 | begin | |
| 22 | 24 | result := 2 * FibonacciNumber( n + 1) - 1 | |
| 23 | 25 | end; | |
| 24 | 26 | ``` | |
| 25 | 27 | ||
| 26 | 28 | --- | |
| 27 | 29 | *From the Free Pascal wiki, page "Leonardo number", as it stood on 2020-02-19 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
