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

View File

@@ -51,7 +51,7 @@ namespace ProjectEulerCS.Problems{
} }
//Start the timer //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 //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){ for (int cnt = 1; cnt <= TOP_NUM; ++cnt){
@@ -64,7 +64,7 @@ namespace ProjectEulerCS.Problems{
} }
//Stop the timer //Stop the timer
_timer.Stop(); timer.Stop();
//Thow a flag to show the problem is solved //Thow a flag to show the problem is solved
solved = true; solved = true;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -64,7 +64,7 @@ namespace ProjectEulerCS.Problems{
} }
//Start the timer //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 //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){ for(int firstNum = START_NUM;firstNum <= END_NUM;++firstNum){
@@ -89,7 +89,7 @@ namespace ProjectEulerCS.Problems{
palindromes.Sort(); palindromes.Sort();
//Stop the timer //Stop the timer
_timer.Stop(); timer.Stop();
//Throw a flag to show the problem is solved //Throw a flag to show the problem is solved
solved = true; solved = true;

View File

@@ -50,7 +50,7 @@ namespace ProjectEulerCS.Problems{
} }
//Start the timer //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 //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 bool numFound = false; //A flag for finding the divisible number
@@ -75,7 +75,7 @@ namespace ProjectEulerCS.Problems{
smallestNum = currentNum; smallestNum = currentNum;
//Stop the timer //Stop the timer
_timer.Stop(); timer.Stop();
//Throw a flag to show the problem is solved //Throw a flag to show the problem is solved
solved = true; solved = true;

View File

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

View File

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

View File

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

View File

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