Leonardo number

From Free Pascal wiki
Revision as of 02:29, 19 February 2020 by Trev (talk | contribs) (Fixed syntax highlighting)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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;