Added function to get a specific fibbonacci number

This commit is contained in:
2021-04-08 13:43:10 -04:00
parent cc2cf70630
commit 3eb91a703b

View File

@@ -498,6 +498,43 @@ export function getProdBig(ary: bigint[]): bigint{
return prod;
}
export function getFib(goalSubscript: number): number{
//Setup the variables
let fibNums: number[] = [1, 1, 0]; //A list to keep track of the Fibonacci numbers. It need only be 3 long because we only need the one we are working on and the last 2
//If the number is <= 0 return 0
if(goalSubscript <= 0){
return 0;
}
//Loop through the list, generating Fibonacci numbers until it finds the correct subscript
let fibLoc: number = 2;
for(fibLoc = 2;fibLoc < goalSubscript;++fibLoc){
fibNums[fibLoc % 3] = fibNums[(fibLoc - 1) % 3] + fibNums[(fibLoc - 2) % 3];
}
//Return the proper number. The location counter is 1 off of the subscript
return fibNums[(fibLoc - 1) % 3];
}
export function getFibBig(goalSubscript: bigint): bigint{
//Setup the varibles
let fibNums: bigint[] = [1n, 1n, 0n]; //A list to keep track of the Fibonacci numbers. It need only be 3 long because we only need the one we are working on and the last 2
//If the number is <= 0 return 0
if(goalSubscript <= 0n){
return 0n;
}
//Loop through the list, generating Fibonacci numbers until it finds the correct subscript
let fibLoc: bigint = 2n;
for(fibLoc = 2n;fibLoc < goalSubscript;++fibLoc){
fibNums[Number(fibLoc % 3n)] = fibNums[Number((fibLoc - 1n) % 3n)] + fibNums[Number((fibLoc - 2n) % 3n)];
}
//Return the proper number. The location counter is 1 off of the subscript
return fibNums[Number((fibLoc - 1n) % 3n)];
}
//This is a function that creates all permutations of a string and returns a vector of those permutations
export function getPermutations(master: string): string[]{
return getPermutationsHelper(master, 0);