How to resolve the algorithm Leonardo numbers step by step in the Action! programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Leonardo numbers step by step in the Action! programming language

Table of Contents

Problem Statement

Leonardo numbers   are also known as the   Leonardo series.

The   Leonardo numbers   are a sequence of numbers defined by:

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:

(The last task requirement will produce the Fibonacci numbers.)

Show all output here on this page.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Leonardo numbers step by step in the Action! programming language

Source code in the action! programming language

CARD FUNC Leonardo(BYTE n)
  CARD curr,prev,tmp

  IF n<=1 THEN
    RETURN (1)
  FI

  prev=1
  curr=1
  DO
    tmp=prev
    prev=curr
    curr==+tmp+1
    n==-1
  UNTIL n=1
  OD
RETURN (curr)

PROC Main()
  BYTE n
  CARD l

  Put(125) ;clear screen

  FOR n=0 TO 22 ;limited to 22 because of CARD limitations
  DO
    l=Leonardo(n)
    IF n MOD 2=0 THEN
      Position(2,n/2+1)
    ELSE
      Position(21,n/2+1)
    FI
    PrintF("L(%B)=%U",n,l)
  OD
RETURN

  

You may also check:How to resolve the algorithm Proper divisors step by step in the Racket programming language
You may also check:How to resolve the algorithm Word wrap step by step in the Erlang programming language
You may also check:How to resolve the algorithm Literals/String step by step in the Elixir programming language
You may also check:How to resolve the algorithm Rot-13 step by step in the Wart programming language
You may also check:How to resolve the algorithm Soundex step by step in the COBOL programming language