mirror of
https://bitbucket.org/Mattrixwv/csclasses.git
synced 2025-12-06 18:23:58 -05:00
Various bug fixes
This commit is contained in:
@@ -32,7 +32,18 @@ namespace mee{
|
|||||||
//These are a few functions that help with some utility within the class
|
//These are a few functions that help with some utility within the class
|
||||||
//Returns the sqrt of the BigInt passed to it
|
//Returns the sqrt of the BigInt passed to it
|
||||||
public static BigInteger BigIntegerSqrt(BigInteger num){
|
public static BigInteger BigIntegerSqrt(BigInteger num){
|
||||||
return (BigInteger)Math.Ceiling(Math.Exp(BigInteger.Log(num) / 2));
|
BigInteger sqrt;
|
||||||
|
|
||||||
|
//Get the sqrt from the general formula
|
||||||
|
double tempSqrt = Math.Exp(BigInteger.Log(num) / 2);
|
||||||
|
//Account for floating-point rounding errors
|
||||||
|
if((BigInteger)(tempSqrt * tempSqrt) < num){
|
||||||
|
sqrt = (BigInteger)Math.Ceiling(tempSqrt);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
sqrt = (BigInteger)tempSqrt;
|
||||||
|
}
|
||||||
|
return sqrt;
|
||||||
}
|
}
|
||||||
|
|
||||||
//These functions return a list of all Fibonacci numbers <= goalNumber
|
//These functions return a list of all Fibonacci numbers <= goalNumber
|
||||||
@@ -557,7 +568,7 @@ namespace mee{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Start at 3 and loop through all numbers < sqrt(goalNumber) looking for a number that divides it evenly
|
//Start at 3 and loop through all numbers < sqrt(goalNumber) looking for a number that divides it evenly
|
||||||
double topPossibleDivisor = Math.Exp(BigInteger.Log(goalNumber) / 2);
|
double topPossibleDivisor = (double)BigIntegerSqrt(goalNumber);
|
||||||
for(long possibleDivisor = 1;possibleDivisor <= topPossibleDivisor;++possibleDivisor){
|
for(long possibleDivisor = 1;possibleDivisor <= topPossibleDivisor;++possibleDivisor){
|
||||||
//If you find one add it and the number it creates to the list
|
//If you find one add it and the number it creates to the list
|
||||||
if((goalNumber % possibleDivisor) == 0){
|
if((goalNumber % possibleDivisor) == 0){
|
||||||
@@ -593,21 +604,36 @@ namespace mee{
|
|||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
public static int GetProd(List<int> ary){
|
public static int GetProd(List<int> ary){
|
||||||
int prod = 1;
|
//If a blank list was passed to the function return 0 as the product
|
||||||
|
if(ary.Capacity == 0){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int prod = 1; //Start at 1 because x * 1 = x
|
||||||
foreach(int num in ary){
|
foreach(int num in ary){
|
||||||
prod *= num;
|
prod *= num;
|
||||||
}
|
}
|
||||||
return prod;
|
return prod;
|
||||||
}
|
}
|
||||||
public static long GetProd(List<long> ary){
|
public static long GetProd(List<long> ary){
|
||||||
long prod = 1;
|
//If a blank list was passed to the function return 0 as the product
|
||||||
|
if(ary.Capacity == 0){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
long prod = 1; //Start at 1 because x * 1 = x
|
||||||
foreach(long num in ary){
|
foreach(long num in ary){
|
||||||
prod *= num;
|
prod *= num;
|
||||||
}
|
}
|
||||||
return prod;
|
return prod;
|
||||||
}
|
}
|
||||||
public static BigInteger GetProd(List<BigInteger> ary){
|
public static BigInteger GetProd(List<BigInteger> ary){
|
||||||
BigInteger prod = 1;
|
//If a blank list was passed to the function return 0 as the product
|
||||||
|
if(ary.Capacity == 0){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
BigInteger prod = 1; //Start at 1 because x * 1 = x
|
||||||
foreach(BigInteger num in ary){
|
foreach(BigInteger num in ary){
|
||||||
prod *= num;
|
prod *= num;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user