Changed name of timer

This commit is contained in:
2020-08-27 12:06:44 -04:00
parent 27b7b2e518
commit b9b5d88191
20 changed files with 47 additions and 45 deletions

View File

@@ -24,13 +24,13 @@ namespace ProjectEulerCS{
get{ return _description; }
}
protected bool solved; //Shows whether the problem has already been solved
protected mee.Stopwatch _timer = new mee.Stopwatch();
protected mee.Stopwatch timer = new mee.Stopwatch();
public mee.Stopwatch Timer{
get{
if(!solved){
throw new Unsolved();
}
return _timer;
return timer;
}
}
public string Time{
@@ -38,7 +38,7 @@ namespace ProjectEulerCS{
if(!solved){
throw new Unsolved();
}
return _timer.GetStr();
return timer.GetStr();
}
}
@@ -53,7 +53,7 @@ namespace ProjectEulerCS{
public abstract void Solve();
//Reset the problem so it can be run again
public virtual void Reset(){
_timer.Reset();
timer.Reset();
solved = false;
_result = null;
}

View File

@@ -51,7 +51,7 @@ namespace ProjectEulerCS.Problems{
}
//Start the timer
_timer.Start();
timer.Start();
//Check every number < 1000 to see if it is a multiple of 3 or 5. If it is add it to the running sum
for (int cnt = 1; cnt <= TOP_NUM; ++cnt){
@@ -64,7 +64,7 @@ namespace ProjectEulerCS.Problems{
}
//Stop the timer
_timer.Stop();
timer.Stop();
//Thow a flag to show the problem is solved
solved = true;

View File

@@ -55,13 +55,13 @@ namespace ProjectEulerCS{
}
//Start the timer
_timer.Start();
timer.Start();
//Get the sum of all prime numbers < GOAL_NUMBER
long sum = mee.Algorithms.GetPrimes(GOAL_NUMBER).Sum();
//Stop the timer
_timer.Stop();
timer.Stop();
//Throw a flag to show the problem is solved
solved = true;

View File

@@ -109,7 +109,7 @@ namespace ProjectEulerCS.Problems{
List<int> currentProduct = new List<int>() {0, 0, 0, 0};
//Start the timer
_timer.Start();
timer.Start();
//Loop through every row and column
for(int row = 0;row < grid.GetLength(0);++row){
@@ -187,7 +187,7 @@ namespace ProjectEulerCS.Problems{
}
//Stop the timer
_timer.Stop();
timer.Stop();
//Throw a flag to show the problem is solved
solved = true;

View File

@@ -87,7 +87,7 @@ namespace ProjectEulerCS.Problems{
bool foundNumber = false; //To flag whether the number has been found
//Start the timer
_timer.Start();
timer.Start();
//Loop until you fin the appropriate number
while((!foundNumber) && (sum > 0)){
@@ -104,7 +104,7 @@ namespace ProjectEulerCS.Problems{
}
//Stop the timer
_timer.Stop();
timer.Stop();
//Throw a flag to show the problem is sovled
solved = true;

View File

@@ -269,13 +269,13 @@ namespace ProjectEulerCS.Problems{
}
//Start the timer
_timer.Start();
timer.Start();
//Get the sum of all the number
sum = mee.Algorithms.GetSum(nums);
//Stop the timer
_timer.Stop();
timer.Stop();
//Throw a flag to show the problem is solved
solved = true;

View File

@@ -67,7 +67,7 @@ namespace ProjectEulerCS.Problems{
}
//Start the timer
_timer.Start();
timer.Start();
//Loop through all numbers <= MAX_NUM and check them against the series
for(long currentNum = 1;currentNum <= MAX_NUM;++currentNum){
@@ -80,7 +80,7 @@ namespace ProjectEulerCS.Problems{
}
//Stop the timer
_timer.Stop();
timer.Stop();
//Throw a flag to show the problem is solved
solved = true;

View File

@@ -53,14 +53,14 @@ namespace ProjectEulerCS.Problems{
}
//Start the timer
_timer.Start();
timer.Start();
//We write this as a recursive function
//When in a location it always moves right first, then down
Move(0, 0);
//Stop the timer
_timer.Stop();
timer.Stop();
//Throw a flag to show the problem is solved
solved = true;

View File

@@ -67,7 +67,7 @@ namespace ProjectEulerCS.Problems{
}
//Start the timer
_timer.Start();
timer.Start();
//Get the number
num = BigInteger.Pow(NUM_TO_POWER, POWER);
@@ -81,7 +81,7 @@ namespace ProjectEulerCS.Problems{
}
//Stop the timer
_timer.Stop();
timer.Stop();
//Throw a flag to show the problem is solved
solved = true;

View File

@@ -56,7 +56,7 @@ namespace ProjectEulerCS.Problems{
}
//Start the timer
_timer.Start();
timer.Start();
//Start with 1 and increment
for(int num = START_NUM;num <= STOP_NUM;++num){
@@ -67,7 +67,7 @@ namespace ProjectEulerCS.Problems{
}
//Stop the timer
_timer.Stop();
timer.Stop();
//Throw a flag to show the problem is solved
solved = true;

View File

@@ -200,7 +200,7 @@ namespace ProjectEulerCS.Problems{
}
//Start the timer
_timer.Start();
timer.Start();
//Invert the list
Invert(list);
@@ -245,7 +245,7 @@ namespace ProjectEulerCS.Problems{
}
//Stop the timer
_timer.Stop();
timer.Stop();
//Invert the list again so it is correct
Invert(list);

View File

@@ -61,7 +61,7 @@ namespace ProjectEulerCS.Problems{
}
//Start the timer
_timer.Start();
timer.Start();
//Run for all years 1901-2000
for(int year = START_YEAR;year <= END_YEAR;++year){
@@ -78,7 +78,7 @@ namespace ProjectEulerCS.Problems{
}
//Stop the timer
_timer.Stop();
timer.Stop();
//Throw a flag to show the problem is solved
solved = true;

View File

@@ -56,7 +56,7 @@ namespace ProjectEulerCS.Problems{
}
//Start the timer
_timer.Start();
timer.Start();
//Get a list of all fibonacci numbers < 4,000,000
List<int> fibNums = mee.Algorithms.GetAllFib(TOP_NUM);
@@ -69,7 +69,7 @@ namespace ProjectEulerCS.Problems{
}
//Stop the timer
_timer.Stop();
timer.Stop();
//Throw a flag to show the problem is solved
solved = true;

View File

@@ -66,14 +66,14 @@ namespace ProjectEulerCS.Problems{
}
//Star the timer
_timer.Start();
timer.Start();
//Get all the factors of the number
factors = mee.Algorithms.GetFactors(GOAL_NUMBER);
//THe last element should be the largest factor
//Stop the timer
_timer.Stop();
timer.Stop();
//Throw a flag to show the problem is solved
solved = true;

View File

@@ -64,7 +64,7 @@ namespace ProjectEulerCS.Problems{
}
//Start the timer
_timer.Start();
timer.Start();
//Start at the first 3-digit number and check every one up to the last 3-digit number
for(int firstNum = START_NUM;firstNum <= END_NUM;++firstNum){
@@ -89,7 +89,7 @@ namespace ProjectEulerCS.Problems{
palindromes.Sort();
//Stop the timer
_timer.Stop();
timer.Stop();
//Throw a flag to show the problem is solved
solved = true;

View File

@@ -50,7 +50,7 @@ namespace ProjectEulerCS.Problems{
}
//Start the timer
_timer.Start();
timer.Start();
//Start at 20 because it must at least be divisible by 20. Increment by 2 because it must be an even number to be divisible by 2
bool numFound = false; //A flag for finding the divisible number
@@ -75,7 +75,7 @@ namespace ProjectEulerCS.Problems{
smallestNum = currentNum;
//Stop the timer
_timer.Stop();
timer.Stop();
//Throw a flag to show the problem is solved
solved = true;

View File

@@ -74,7 +74,7 @@ namespace ProjectEulerCS.Problems{
}
//Start the timer
_timer.Start();
timer.Start();
//Run through all numbers and add them to the appropriate sums
for(int currentNum = START_NUM;currentNum <= END_NUM;++currentNum){
@@ -85,7 +85,7 @@ namespace ProjectEulerCS.Problems{
squareOfSum *= squareOfSum;
//Stop the timer
_timer.Stop();
timer.Stop();
//Throw a flag to show the problem is solved
solved = true;

View File

@@ -55,13 +55,13 @@ namespace ProjectEulerCS.Problems{
}
//Start the timer
_timer.Start();
timer.Start();
//Setup the variables
primes = mee.Algorithms.GetNumPrimes(NUMBER_OF_PRIMES); //Holds the prime numbers
//Stop the timer
_timer.Stop();
timer.Stop();
//Throw a flag to show the problem is solved
solved = true;

View File

@@ -88,7 +88,7 @@ namespace ProjectEulerCS.Problems{
}
//Start the timer
_timer.Start();
timer.Start();
//Cycle through the string of numbers looking for the maximum product
for(int cnt = 12;cnt < NUMBER.Length;++cnt){
@@ -102,7 +102,7 @@ namespace ProjectEulerCS.Problems{
}
//Stop the timer
_timer.Stop();
timer.Stop();
//Throw a flag to show the problem is solved
solved = true;

View File

@@ -28,6 +28,8 @@ using System;
namespace ProjectEulerCS{
public class Problem9 : Problem{
//Variables
//Static varibles
private const int GOAL_SUM = 1000; //The number that we want the sum of a, b, and c to equal
//Instance variables
private int a; //Holds the size of the first side
public int SideA{
@@ -83,21 +85,21 @@ namespace ProjectEulerCS{
}
//Start the timer
_timer.Start();
timer.Start();
//Loop through all possible a's
while((a < 1000) && !found){
while((a < GOAL_SUM) && !found){
b = a + 1; //b must be larget than a
c = Math.Sqrt((a * a) + (b * b)); //Compute the hyp
//Loop through all possible b's for this a
while((a + b + c) < 1000){
while((a + b + c) < GOAL_SUM){
++b;
c = Math.Sqrt((a * a) + (b * b));
}
//If the sum == 1000 you found the number, otherwise go to the next possible a
if((a + b + c) == 1000){
if((a + b + c) == GOAL_SUM){
found = true;
}
else{
@@ -106,7 +108,7 @@ namespace ProjectEulerCS{
}
//Stop the timer
_timer.Stop();
timer.Stop();
//Throw a flag to show the problem is solved
solved = true;