diff --git a/.gitignore b/.gitignore index 4287ca8..94cfd5b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -# \ No newline at end of file +#Executables +*.exe \ No newline at end of file diff --git a/makefile b/makefile new file mode 100644 index 0000000..e69de29 diff --git a/src/Problems/Problem.cs b/src/Problems/Problem.cs new file mode 100644 index 0000000..590d58d --- /dev/null +++ b/src/Problems/Problem.cs @@ -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; + } + } +} diff --git a/src/Problems/Problem1.cs b/src/Problems/Problem1.cs new file mode 100644 index 0000000..7f65396 --- /dev/null +++ b/src/Problems/Problem1.cs @@ -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 . +*/ + + +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; + } + } +} \ No newline at end of file diff --git a/src/Problems/ProjectEuler.cs b/src/Problems/ProjectEuler.cs new file mode 100644 index 0000000..784e478 --- /dev/null +++ b/src/Problems/ProjectEuler.cs @@ -0,0 +1,8 @@ +namespace mee{ + public class ProjectEuler{ + public static void Main(string[] args){ + Problem1 prob = new Problem1(); + prob.solve(); + } + } +} \ No newline at end of file