Added start of project

This commit is contained in:
2020-08-14 20:56:02 -04:00
parent 3f72bec192
commit 4eb8c72ddd
5 changed files with 125 additions and 1 deletions

3
.gitignore vendored
View File

@@ -1 +1,2 @@
# #Executables
*.exe

0
makefile Normal file
View File

38
src/Problems/Problem.cs Normal file
View File

@@ -0,0 +1,38 @@
//ProjectEuler/ProjectEulerCS/src/Problems/Problem.cs
//Matthew Ellison
// Created: 08-14-20
//Modified: 08-14-20
//This is the base class for the rest of the problems
namespace mee{
public abstract class Problem{
//Variables
//Instance variables
//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; }
}
protected readonly string _description; //Holds the description of the problem
public string description{
get{ return _description; }
}
protected bool solved; //Shows whether the problem has already been solved
//Constructor
public Problem(string description){
this._description = description;
}
//Operations functions
//Solve the problem
public abstract void solve();
//Reset the problem so it can be run again
public virtual void reset(){
//timer.reset();
solved = false;
_result = null;
}
}
}

77
src/Problems/Problem1.cs Normal file
View File

@@ -0,0 +1,77 @@
//ProjectEuler/ProjectEulerCS/src/Problems/Problem1.cs
//Matthew Ellison
// 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
/*
Copyright (C) 2020 Matthew Ellison
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace mee{
public class Problem1 : Problem{
//Variables
private const int TOP_NUM = 999; //THe largest number to tbe checked
//Instance variables
private int fullSum; //The sum of all the numbers
public int sum{
get{ return fullSum; }
}
//Functions
//Constructor
public Problem1() : base("What is the sum of all the multiples of 3 or 5 that are less than 1000"){
fullSum = 0;
}
//Operational functions
//Solve the problem
public override void solve(){
//If the problem has already been solved do nothing and end the function
if(solved){
return;
}
//Start the timer
//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){
if((cnt %3) == 0){
fullSum += cnt;
}
else if((cnt % 5) == 0){
fullSum += cnt;
}
}
//Stop the timer
//timer.stop();
//Thow a flag to show the problem is solved
solved = true;
//Save the results
_result = "The sum of all numbers < " + (TOP_NUM + 1) + " is " + fullSum;
System.Console.WriteLine(result);
}
//Reset the problem so it can be run again
public override void reset(){
base.reset();
fullSum = 0;
}
}
}

View File

@@ -0,0 +1,8 @@
namespace mee{
public class ProjectEuler{
public static void Main(string[] args){
Problem1 prob = new Problem1();
prob.solve();
}
}
}