Initial commit with a few functions

This commit is contained in:
2020-06-12 19:26:17 -04:00
commit 60af0afba6
5 changed files with 272 additions and 0 deletions

41
src/Algorithms.rs Normal file
View File

@@ -0,0 +1,41 @@
extern crate num;
pub fn getAllFib(goalNumber: u64) -> Vec<u64>{
let mut fibNums = Vec::new(); //A list to save the Fibonacci numbers
//If the number is <= 0 return an empty list
if(goalNumber <= 0){
return fibNums;
}
//This means that at least 2 1's are elements
fibNums.push(1);
fibNums.push(1);
//Loop to generate the rest of the Fibonacci numbers
while(fibNums[fibNums.len() - 1] <= goalNumber){
fibNums.push(fibNums[fibNums.len() - 1] + fibNums[fibNums.len() - 2]);
}
//At this point the most recent number is > goalNumber, so remove it and return the rest of the list
fibNums.remove(fibNums.len() - 1);
return fibNums;
}
pub fn getAllFibBig(goalNumber: num::BigInt) -> Vec<num::BigInt>{
let mut fibNums = Vec::new(); //A list to save the Fibonacci numbers in
//If the number is <= 0 return an empty list
if(goalNumber <= num::BigInt::from(0)){
return fibNums;
}
//This means that at least 2 1's are elements
fibNums.push(num::BigInt::from(1));
fibNums.push(num::BigInt::from(1));
while(fibNums[fibNums.len() - 1] <= goalNumber){
fibNums.push(&fibNums[fibNums.len() - 1] + &fibNums[fibNums.len() - 2]);
}
//At this point the most recent number is > goalNumber, so remove it and return the rest of the list
fibNums.remove(fibNums.len() - 1);
return fibNums;
}