Leonardo number

From Free Pascal wiki
Jump to navigationJump to search

Deutsch (de) English (en) suomi (fi) français (fr) русский (ru)

Leonardo number

The Leonardo Sequence is the series of numbers:

1, 1, 3, 5, 9, 15, 25 ...

Recursive way

function LeonardoNumber( n : integer ):integer;
begin
  if n > 1 then result := LeonardoNumber( n - 1 ) + LeonardoNumber( n - 2 ) + 1
    else result := 1;
end;

Making use of Fibonacci numbers

function LeonardoNumber2( n : integer ):integer;
begin
  result := 2 * FibonacciNumber( n + 1) - 1
end;