diff --git a/CSClasses/Algorithms.cs b/CSClasses/Algorithms.cs index c2ad08e..18ed00a 100644 --- a/CSClasses/Algorithms.cs +++ b/CSClasses/Algorithms.cs @@ -30,7 +30,7 @@ using System.Numerics; namespace mee{ public class Algorithms{ //These functions return a list of all Fibonacci numbers <= goalNumber - public static List getAllFib(int goalNumber){ + public static List GetAllFib(int goalNumber){ //Setup the variables List fibNums = new List(); @@ -52,7 +52,7 @@ namespace mee{ fibNums.RemoveAt(fibNums.Count - 1); return fibNums; } - public static List getAllFib(long goalNumber){ + public static List GetAllFib(long goalNumber){ //Setup the variables List fibNums = new List(); @@ -74,7 +74,7 @@ namespace mee{ fibNums.RemoveAt(fibNums.Count - 1); return fibNums; } - public static List getAllFib(BigInteger goalNumber){ + public static List GetAllFib(BigInteger goalNumber){ //Setup the variables List fibNums = new List(); @@ -97,10 +97,10 @@ namespace mee{ return fibNums; } //These functions return all factors of goalNumber - public static List getFactors(int goalNumber){ + public static List GetFactors(int goalNumber){ //You need to get all the primes that could be factors of this number so you can test them int topPossiblePrime = (int)Math.Ceiling(Math.Sqrt(goalNumber)); - List primes = getPrimes(topPossiblePrime); + List primes = GetPrimes(topPossiblePrime); List factors = new List(); //YOu need to step through each prime and see if it is a factor in the number @@ -128,10 +128,10 @@ namespace mee{ //Return the list of factors return factors; } - public static List getFactors(long goalNumber){ + public static List GetFactors(long goalNumber){ //You need to get all the primes that could be factors of this number so you can test them long topPossiblePrime = (long)Math.Ceiling(Math.Sqrt(goalNumber)); - List primes = getPrimes(topPossiblePrime); + List primes = GetPrimes(topPossiblePrime); List factors = new List(); //YOu need to step through each prime and see if it is a factor in the number @@ -159,10 +159,10 @@ namespace mee{ //Return the list of factors return factors; } - public static List getFactors(BigInteger goalNumber){ + public static List GetFactors(BigInteger goalNumber){ //You need to get all the primes that could be factors of this number so you can test them BigInteger topPossiblePrime = (BigInteger)Math.Exp(BigInteger.Log(goalNumber) / 2); - List primes = getPrimes(topPossiblePrime); + List primes = GetPrimes(topPossiblePrime); List factors = new List(); //YOu need to step through each prime and see if it is a factor in the number @@ -191,7 +191,7 @@ namespace mee{ return factors; } //These functions return a list with all the prime number <= goalNumber - public static List getPrimes(int goalNumber){ + public static List GetPrimes(int goalNumber){ List primes = new List(); //Holds the prime numbers bool foundFactor = false; //A flag for whether a factor of the current number has been found @@ -235,7 +235,7 @@ namespace mee{ primes.Sort(); return primes; } - public static List getPrimes(long goalNumber){ + public static List GetPrimes(long goalNumber){ List primes = new List(); //Holds the prime numbers bool foundFactor = false; //A flag for whether a factor of the current number has been found @@ -279,7 +279,7 @@ namespace mee{ primes.Sort(); return primes; } - public static List getPrimes(BigInteger goalNumber){ + public static List GetPrimes(BigInteger goalNumber){ List primes = new List(); //Holds the prime numbers bool foundFactor = false; //A flag for whether a factor of the current number has been found @@ -325,7 +325,7 @@ namespace mee{ return primes; } //This function gets a certain number of primes - public static List getNumPrimes(int numberOfPrimes){ + public static List GetNumPrimes(int numberOfPrimes){ List primes = new List(); //Holds the prime numbers bool foundFactor = false; //A flag for whether a factor of the current number has been found @@ -370,7 +370,7 @@ namespace mee{ primes.Sort(); return primes; } - public static List getNumPrimes(long numberOfPrimes){ + public static List GetNumPrimes(long numberOfPrimes){ List primes = new List(); //Holds the prime numbers bool foundFactor = false; //A flag for whether a factor of the current number has been found @@ -415,7 +415,7 @@ namespace mee{ primes.Sort(); return primes; } - public static List getNumPrimes(BigInteger numberOfPrimes){ + public static List GetNumPrimes(BigInteger numberOfPrimes){ List primes = new List(); //Holds the prime numbers bool foundFactor = false; //A flag for whether a factor of the current number has been found @@ -461,34 +461,34 @@ namespace mee{ return primes; } //These functions get a value from combining elements in an array - public static int getSum(List ary){ + public static int GetSum(List ary){ return ary.Sum(); } - public static long getSum(List ary){ + public static long GetSum(List ary){ return ary.Sum(); } - public static BigInteger getSum(List ary){ + public static BigInteger GetSum(List ary){ BigInteger sum = 0; foreach(BigInteger num in ary){ sum += num; } return sum; } - public static int getProd(List ary){ + public static int GetProd(List ary){ int prod = 1; foreach(int num in ary){ prod *= num; } return prod; } - public static long getProd(List ary){ + public static long GetProd(List ary){ long prod = 1; foreach(long num in ary){ prod *= num; } return prod; } - public static BigInteger getProd(List ary){ + public static BigInteger GetProd(List ary){ BigInteger prod = 1; foreach(BigInteger num in ary){ prod *= num; diff --git a/CSClasses/Stopwatch.cs b/CSClasses/Stopwatch.cs index 66b34d2..1da6341 100644 --- a/CSClasses/Stopwatch.cs +++ b/CSClasses/Stopwatch.cs @@ -31,52 +31,52 @@ namespace mee{ public Stopwatch(){ } //Returns a long with the elapsed time in nanoseconds. Used by other functions to get the time before converting it to the correct resolution - private long getTime(){ + private long GetTime(){ return stopwatch.ElapsedTicks; } //Simultates starting a stopwatch - public void start(){ + public void Start(){ stopwatch.Start(); } //Simulates stopping a stopwatch - public void stop(){ + public void Stop(){ stopwatch.Stop(); } //Resets all the variables in teh stopwatch - public void reset(){ + public void Reset(){ stopwatch.Reset(); } //Returns the timer in nanoseconds - public decimal getNano(){ + public decimal GetNano(){ return (decimal)nanosecPerTick * (decimal)stopwatch.ElapsedTicks; } //Returns the timer in microseconds - public decimal getMicro(){ - return getNano() / 1000m; + public decimal GetMicro(){ + return GetNano() / 1000m; } //Returns the timer in milliseconds - public decimal getMilli(){ - return getNano() / 1000000m; + public decimal GetMilli(){ + return GetNano() / 1000000m; } //Returns the timer in seconds - public decimal getSecond(){ - return getNano() / 1000000000m; + public decimal GetSecond(){ + return GetNano() / 1000000000m; } //Returns the timer in minutes - public decimal getMinute(){ - return getNano() / 60000000000m; + public decimal GetMinute(){ + return GetNano() / 60000000000m; } //Returns the timer in hours - public decimal getHour(){ - return getNano() / 3600000000000m; + public decimal GetHour(){ + return GetNano() / 3600000000000m; } //Returns the timer as a string at the 'best' resolution. (Goal is xxx.xxx) - public string getStr(){ + public string GetStr(){ //Get the current duration from time - return getStr(getNano()); + return GetStr(GetNano()); } //Returns a string of the decimal value passed in (assuming the value in nanoseconds) - public static string getStr(decimal nanoseconds){ + public static string GetStr(decimal nanoseconds){ decimal duration = nanoseconds; //Reduce the number to the appropriate number of digits. (xxx.x) //This loop works down to seconds @@ -117,66 +117,66 @@ namespace mee{ } //Overrides default tostring. returns getStr public override string ToString(){ - return getStr(); + return GetStr(); } //Tests public static void Main(string[] args){ System.Console.WriteLine("Testing start/stop"); - testStartStop(); + TestStartStop(); System.Console.WriteLine("start/stop completed successfully"); System.Console.WriteLine("Testing conversion"); - testConversion(); + TestConversion(); System.Console.WriteLine("conversion test completed successfully"); System.Console.WriteLine("Testing stringConversion"); - testStringConversion(); + TestStringConversion(); System.Console.WriteLine("stringConversion completed successfully"); } - public static void testStartStop(){ + public static void TestStartStop(){ Stopwatch timer = new Stopwatch(); - timer.start(); - timer.stop(); + timer.Start(); + timer.Stop(); //If it gets here without throwing an exception everything went well } - public static void testConversion(){ + public static void TestConversion(){ Stopwatch timer = new Stopwatch(); int sum = 0; //Start the timer - timer.start(); + timer.Start(); //Do something to run some time for(int cnt = 0;cnt < NUM_TO_RUN;++cnt){ sum += cnt; } //Stop the timer - timer.stop(); + timer.Stop(); //Assert something so the sum isn't ignored during compile System.Diagnostics.Debug.Assert(sum != 0); //Check that the different resolutions work out correctly - decimal nano = timer.getNano(); - System.Diagnostics.Debug.Assert(timer.getMicro() == (nano / 1000m), "Micro resolution test failed"); - System.Diagnostics.Debug.Assert(timer.getMilli() == (nano / 1000000m), "Milli resolution test failed"); - System.Diagnostics.Debug.Assert(timer.getSecond() == (nano / 1000000000m), "Second resolution test failed"); - System.Diagnostics.Debug.Assert(timer.getMinute() == (nano / 60000000000m), "Minute resolution test failed"); - System.Diagnostics.Debug.Assert(timer.getHour() == (nano / 3600000000000m), "Hour resolution test failed"); + decimal nano = timer.GetNano(); + System.Diagnostics.Debug.Assert(timer.GetMicro() == (nano / 1000m), "Micro resolution test failed"); + System.Diagnostics.Debug.Assert(timer.GetMilli() == (nano / 1000000m), "Milli resolution test failed"); + System.Diagnostics.Debug.Assert(timer.GetSecond() == (nano / 1000000000m), "Second resolution test failed"); + System.Diagnostics.Debug.Assert(timer.GetMinute() == (nano / 60000000000m), "Minute resolution test failed"); + System.Diagnostics.Debug.Assert(timer.GetHour() == (nano / 3600000000000m), "Hour resolution test failed"); } - public static void testStringConversion(){ + public static void TestStringConversion(){ //Test nanoseconds - string results = Stopwatch.getStr(1.0m); + string results = Stopwatch.GetStr(1.0m); System.Diagnostics.Debug.Assert(results == "1.000 nanoseconds", "Failed nanoseconds: " + results); //Test microseconds - results = Stopwatch.getStr(1.0e3m); + results = Stopwatch.GetStr(1.0e3m); System.Diagnostics.Debug.Assert(results == "1.00 microsesconds", "Failed microseconds: " + results); //Test milliseconds - results = Stopwatch.getStr(1.0e6m); + results = Stopwatch.GetStr(1.0e6m); System.Diagnostics.Debug.Assert(results == "1.00 milliseconds", "Failed milliseconds: " + results); //Test seconds - results = Stopwatch.getStr(1.0e9m); + results = Stopwatch.GetStr(1.0e9m); System.Diagnostics.Debug.Assert(results == "1.00 seconds", "Failed seconds: " + results); //Test minutes - results = Stopwatch.getStr(1.0e12m); + results = Stopwatch.GetStr(1.0e12m); System.Diagnostics.Debug.Assert(results == "1.00 minutes", "Failed minutes: " + results); //Test hours - results = Stopwatch.getStr(1.0e13m); + results = Stopwatch.GetStr(1.0e13m); System.Diagnostics.Debug.Assert(results == "1.00 hours", "Failed hours: " + results); } }