Fixed problem with times being incorrect

This commit is contained in:
2020-08-23 04:34:27 -04:00
parent 709fc34c81
commit 4ff84acad5
3 changed files with 46 additions and 16 deletions

View File

@@ -12,25 +12,40 @@ namespace ProjectEulerCS{
//protected const Stopwatch timer = new Stopwatch(); //To time how long it takes to run the algorithm
protected string _result = null; //Holds the results of the problem
public string result{
get { return _result; }
get{
if(!solved){
throw new Unsolved();
}
return _result;
}
}
protected readonly string _description; //Holds the description of the problem
public string description{
get { return _description; }
get{ return _description; }
}
protected bool solved; //Shows whether the problem has already been solved
protected mee.Stopwatch _timer = new mee.Stopwatch();
public mee.Stopwatch timer{
get { return _timer; }
get{
if(!solved){
throw new Unsolved();
}
return _timer;
}
}
public string time{
get { return _timer.getStr(); }
get{
if(!solved){
throw new Unsolved();
}
return _timer.getStr();
}
}
//Constructor
public Problem(string description){
this._description = description;
public Problem(string newDescription){
this._description = newDescription;
}
//Operations functions
@@ -38,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

@@ -3,6 +3,7 @@
// Created: 08-14-20
//Modified: 08-14-20
//What is the sum of all the multiples of 3 or 5 that are less than 1000
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
/*
Copyright (C) 2020 Matthew Ellison
@@ -28,7 +29,12 @@ namespace ProjectEulerCS{
//Instance variables
private int fullSum; //The sum of all the numbers
public int sum{
get { return fullSum; }
get{
if(!solved){
throw new Unsolved();
}
return fullSum;
}
}
//Functions
@@ -45,7 +51,7 @@ namespace ProjectEulerCS{
}
//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){
@@ -58,7 +64,7 @@ namespace ProjectEulerCS{
}
//Stop the timer
timer.stop();
_timer.stop();
//Thow a flag to show the problem is solved
solved = true;
@@ -66,7 +72,6 @@ namespace ProjectEulerCS{
//Save the results
_result = "The sum of all numbers < " + (TOP_NUM + 1) + " is " + fullSum;
}
//Reset the problem so it can be run again
public override void reset(){
base.reset();
@@ -77,5 +82,5 @@ namespace ProjectEulerCS{
/* Results:
The sum of all numbers < 1000 is 233168
It took an average of 73.837 microseconds to run this problem through 100 iterations
It took an average of 1.430 microseconds to run this problem through 100 iterations
*/

View File

@@ -2,7 +2,8 @@
//Matthew Ellison
// Created: 08-23-20
//Modified: 08-23-20
//What is the sum of all the multiples of 3 or 5 that are less than 1000
//The sum of the even Fibonacci numbers less than 4,000,000
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/CSClasses
/*
Copyright (C) 2020 Matthew Ellison
@@ -32,6 +33,14 @@ namespace ProjectEulerCS{
private const int TOP_NUM = 4000000 - 1; //The largest number that will be checked as a fibonacci number
//Instance variables
private int fullSum; //Holds the sum of all the numbers
public int sum{
get{
if(!solved){
throw new Unsolved();
}
return fullSum;
}
}
//Functions
//Constructor
@@ -47,7 +56,7 @@ namespace ProjectEulerCS{
}
//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);
@@ -60,7 +69,7 @@ namespace ProjectEulerCS{
}
//Stop the timer
timer.stop();
_timer.stop();
//Throw a flag to show the problem is solved
solved = true;
@@ -68,6 +77,7 @@ namespace ProjectEulerCS{
//Save the results
_result = "The sum of all even fibonacci numbers <= " + TOP_NUM + " is " + fullSum;
}
//Reset the problem so it can be run again
public override void reset(){
base.reset();
fullSum = 0;
@@ -77,5 +87,5 @@ namespace ProjectEulerCS{
/* Results:
The sum of all even fibonacci numbers <= 3999999 is 4613732
It took an average of 539.165 microseconds to run this problem through 100 iterations
It took an average of 5.810 microseconds to run this problem through 100 iterations
*/