Added function for getting a specific fibonacci num

This commit is contained in:
2020-06-17 18:15:22 -04:00
parent 2c9444579a
commit 523a0cad65
2 changed files with 57 additions and 0 deletions

View File

@@ -39,6 +39,44 @@ pub fn getAllFibBig(goalNumber: num::BigInt) -> Vec<num::BigInt>{
fibNums.remove(fibNums.len() - 1);
return fibNums;
}
//This function returns all the divisors of goalSubscript
pub fn getFib(goalSubscript: i64) -> i64{
//Setup the variables
let mut fibNums = [1, 1, 0];
//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 mut fibLoc = 2;
while(fibLoc < goalSubscript){
fibNums[(fibLoc % 3) as usize] = fibNums[((fibLoc - 1) % 3) as usize] + fibNums[((fibLoc - 2) % 3) as usize];
fibLoc += 1;
}
//Return the proper number. The location counter is 1 off of the subscript
return fibNums[((fibLoc - 1) % 3) as usize];
}
pub fn getFibBig(goalSubscript: num::BigInt) -> num::BigInt{
//Setup the variables
let mut fibNums = [num::BigInt::from(1), num::BigInt::from(1), num::BigInt::from(0)];
//If the number is <= 0 return 0
if(goalSubscript <= num::BigInt::from(0)){
return num::BigInt::from(0);
}
//Loop through the list, generating Fibonacci numbers until it finds the correct subscript
let mut fibLoc = 2;
while(num::BigInt::from(fibLoc) < goalSubscript){
fibNums[(fibLoc % 3) as usize] = &fibNums[((fibLoc - 1) % 3) as usize] + &fibNums[((fibLoc - 2) % 3) as usize];
fibLoc += 1;
}
//Return the proper number. The location counter is 1 off of the subscript
let temp = &fibNums[((fibLoc - 1) % 3) as usize];
return num::BigInt::new(temp.to_u32_digits().0, temp.to_u32_digits().1);
}
//This function returns all factors of goalNumber
pub fn getFactors(mut goalNumber: i64) -> Vec<i64>{