mirror of
https://bitbucket.org/Mattrixwv/rustclasses.git
synced 2025-12-07 02:43:59 -05:00
Added function for getting a specific fibonacci num
This commit is contained in:
@@ -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>{
|
||||
|
||||
Reference in New Issue
Block a user