
Leonardo numbers   are also known as the   Leonardo series.



The   Leonardo numbers   are a sequence of numbers defined by:

       L(0) = 1                                          [1st equation]  
       L(1) = 1                                          [2nd equation]  
       L(n) = L(n-1)  +    L(n-2)   +  1                 [3rd equation]  
                    ─── also ───
       L(n) =      2  *  Fib(n+1)   -  1                 [4th equation]  

   where the   + 1   will herein be known as the   add   number.
   where the   FIB   is the   Fibonacci numbers.


This task will be using the 3rd equation (above) to calculate the Leonardo numbers.


Edsger W. Dijkstra   used   Leonardo numbers   as an integral part of
his   smoothsort   algorithm.



The first few Leonardo numbers are:

    1   1   3   5   9   15   25   41   67   109   177   287   465   753   1219   1973   3193   5167   8361  ··· 



Task

   show the 1st   25   Leonardo numbers, starting at L(0).
   allow the first two Leonardo numbers to be specified   [for L(0) and L(1)].
   allow the   add   number to be specified   (1 is the default).
   show the 1st   25   Leonardo numbers, specifying 0 and 1 for L(0) and L(1), and 0 for the add number.
(The last task requirement will produce the Fibonacci numbers.)



Show all output here on this page.



Related tasks

   Fibonacci number
   Fibonacci n-step number sequences 


See also

   Wikipedia, Leonardo numbers
   Wikipedia, Fibonacci numbers
   OEIS Leonardo numbers


To run:
Start up.
Write "First 25 Leonardo numbers:" on the console.
Show 25 of the Leonardo numbers starting with 1 and 1 and using 1 for the add number.
Write "First 25 Leonardo numbers with L(0)=0, L(1)=1, add=0:" on the console.
Show 25 of the Leonardo numbers starting with 0 and 1 and using 0 for the add number.
Wait for the escape key.
Shut down.
 
To show a number of the Leonardo numbers starting with a first number and a second number and using an add number for the add number:
If the number is less than 2, exit.
Privatize the number.
Privatize the first number.
Privatize the second number.
Subtract 2 from the number.
Write the first number then " " then the second number on the console without advancing.
Loop.
If a counter is past the number, write "" on the console; exit.
Swap the first number with the second number.
Put the first number plus the second number plus the add number into the second number.
Write the second number then " " on the console without advancing.
Repeat.