Add More Tests (#4148)

This commit is contained in:
Volodymyr Labliuk
2023-04-08 12:56:07 -04:00
committed by GitHub
parent f35e9a7d81
commit 7779c18ef6
6 changed files with 105 additions and 30 deletions

View File

@ -1,20 +1,23 @@
package com.thealgorithms.maths;
/**
* https://en.wikipedia.org/wiki/Leonardo_number
*/
public class LeonardoNumber {
/**
* Calculate nth Leonardo Number (1, 1, 3, 5, 9, 15, 25, 41, 67, 109, 177, ...)
*
* @param n the index of Leonardo Number to calculate
* @return nth number of Leonardo sequences
*/
public static int leonardoNumber(int n) {
if (n < 0) {
return 0;
throw new ArithmeticException();
}
if (n == 0 || n == 1) {
return 1;
}
return (leonardoNumber(n - 1) + leonardoNumber(n - 2) + 1);
}
public static void main(String args[]) {
for (int i = 0; i < 20; i++) {
System.out.print(leonardoNumber(i) + " ");
}
}
}