How to resolve the algorithm Leonardo numbers step by step in the Bash programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Leonardo numbers step by step in the Bash 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 Bash programming language
Source code in the bash programming language
#!/bin/bash
function leonardo_number () {
L0_value=${2:-1}
L1_value=${3:-1}
Add=${4:-1}
leonardo_numbers=($L0_value $L1_value)
for (( i = 2; i < $1; ++i))
do
leonardo_numbers+=( $((leonardo_numbers[i-1] + leonardo_numbers[i-2] + Add)) )
done
echo "${leonardo_numbers[*]}"
}
You may also check:How to resolve the algorithm Fractran step by step in the bash programming language
You may also check:How to resolve the algorithm Sieve of Eratosthenes step by step in the Bash programming language
You may also check:How to resolve the algorithm Sorting algorithms/Insertion sort step by step in the Bash programming language
You may also check:How to resolve the algorithm Sorting algorithms/Bubble sort step by step in the bash programming language
You may also check:How to resolve the algorithm Bitmap/Bresenham's line algorithm step by step in the bash programming language