mirror of
https://bitbucket.org/Mattrixwv/projecteulercs.git
synced 2026-02-03 19:52:36 -05:00
Fixed problem with times being incorrect
This commit is contained in:
@@ -12,25 +12,40 @@ namespace ProjectEulerCS{
|
|||||||
//protected const Stopwatch timer = new Stopwatch(); //To time how long it takes to run the algorithm
|
//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
|
protected string _result = null; //Holds the results of the problem
|
||||||
public string result{
|
public string result{
|
||||||
get { return _result; }
|
get{
|
||||||
|
if(!solved){
|
||||||
|
throw new Unsolved();
|
||||||
|
}
|
||||||
|
return _result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
protected readonly string _description; //Holds the description of the problem
|
protected readonly string _description; //Holds the description of the problem
|
||||||
public string description{
|
public string description{
|
||||||
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 { return _timer; }
|
get{
|
||||||
|
if(!solved){
|
||||||
|
throw new Unsolved();
|
||||||
|
}
|
||||||
|
return _timer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public string time{
|
public string time{
|
||||||
get { return _timer.getStr(); }
|
get{
|
||||||
|
if(!solved){
|
||||||
|
throw new Unsolved();
|
||||||
|
}
|
||||||
|
return _timer.getStr();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Constructor
|
//Constructor
|
||||||
public Problem(string description){
|
public Problem(string newDescription){
|
||||||
this._description = description;
|
this._description = newDescription;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Operations functions
|
//Operations functions
|
||||||
@@ -38,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;
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
// Created: 08-14-20
|
// Created: 08-14-20
|
||||||
//Modified: 08-14-20
|
//Modified: 08-14-20
|
||||||
//What is the sum of all the multiples of 3 or 5 that are less than 1000
|
//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
|
Copyright (C) 2020 Matthew Ellison
|
||||||
|
|
||||||
@@ -28,7 +29,12 @@ namespace ProjectEulerCS{
|
|||||||
//Instance variables
|
//Instance variables
|
||||||
private int fullSum; //The sum of all the numbers
|
private int fullSum; //The sum of all the numbers
|
||||||
public int sum{
|
public int sum{
|
||||||
get { return fullSum; }
|
get{
|
||||||
|
if(!solved){
|
||||||
|
throw new Unsolved();
|
||||||
|
}
|
||||||
|
return fullSum;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Functions
|
//Functions
|
||||||
@@ -45,7 +51,7 @@ namespace ProjectEulerCS{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//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){
|
||||||
@@ -58,7 +64,7 @@ namespace ProjectEulerCS{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//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;
|
||||||
@@ -66,7 +72,6 @@ namespace ProjectEulerCS{
|
|||||||
//Save the results
|
//Save the results
|
||||||
_result = "The sum of all numbers < " + (TOP_NUM + 1) + " is " + fullSum;
|
_result = "The sum of all numbers < " + (TOP_NUM + 1) + " is " + fullSum;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Reset the problem so it can be run again
|
//Reset the problem so it can be run again
|
||||||
public override void reset(){
|
public override void reset(){
|
||||||
base.reset();
|
base.reset();
|
||||||
@@ -77,5 +82,5 @@ namespace ProjectEulerCS{
|
|||||||
|
|
||||||
/* Results:
|
/* Results:
|
||||||
The sum of all numbers < 1000 is 233168
|
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
|
||||||
*/
|
*/
|
||||||
@@ -2,7 +2,8 @@
|
|||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 08-23-20
|
// Created: 08-23-20
|
||||||
//Modified: 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
|
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
|
private const int TOP_NUM = 4000000 - 1; //The largest number that will be checked as a fibonacci number
|
||||||
//Instance variables
|
//Instance variables
|
||||||
private int fullSum; //Holds the sum of all the numbers
|
private int fullSum; //Holds the sum of all the numbers
|
||||||
|
public int sum{
|
||||||
|
get{
|
||||||
|
if(!solved){
|
||||||
|
throw new Unsolved();
|
||||||
|
}
|
||||||
|
return fullSum;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Functions
|
//Functions
|
||||||
//Constructor
|
//Constructor
|
||||||
@@ -47,7 +56,7 @@ namespace ProjectEulerCS{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//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);
|
||||||
@@ -60,7 +69,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;
|
||||||
@@ -68,6 +77,7 @@ namespace ProjectEulerCS{
|
|||||||
//Save the results
|
//Save the results
|
||||||
_result = "The sum of all even fibonacci numbers <= " + TOP_NUM + " is " + fullSum;
|
_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(){
|
public override void reset(){
|
||||||
base.reset();
|
base.reset();
|
||||||
fullSum = 0;
|
fullSum = 0;
|
||||||
@@ -77,5 +87,5 @@ namespace ProjectEulerCS{
|
|||||||
|
|
||||||
/* Results:
|
/* Results:
|
||||||
The sum of all even fibonacci numbers <= 3999999 is 4613732
|
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
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user