From 0caa043b59f93cc29b347399595163937139167c Mon Sep 17 00:00:00 2001 From: Mattrixwv Date: Sat, 11 Jul 2020 13:35:37 -0400 Subject: [PATCH] Updated various typoes and removed some unneeded code --- Headers/Problem.hpp | 3 --- Headers/Problem1.hpp | 1 - Headers/Problem10.hpp | 4 ++-- Headers/Problem12.hpp | 4 ++-- Headers/Problem15.hpp | 2 +- Headers/Problem17.hpp | 3 ++- Headers/Problem6.hpp | 2 +- Headers/Problem9.hpp | 6 +++--- Source/Problem1.cpp | 10 ++-------- Source/Problem10.cpp | 3 ++- Source/Problem13.cpp | 1 + Source/Problem14.cpp | 2 +- Source/Problem15.cpp | 8 ++++---- Source/Problem17.cpp | 5 +++-- Source/Problem2.cpp | 2 +- Source/Problem31.cpp | 6 +++++- Source/Problem67.cpp | 2 +- 17 files changed, 31 insertions(+), 33 deletions(-) diff --git a/Headers/Problem.hpp b/Headers/Problem.hpp index 3e10ead..e903af1 100644 --- a/Headers/Problem.hpp +++ b/Headers/Problem.hpp @@ -37,14 +37,11 @@ protected: public: //Constructors Problem() : solved(false){ - } Problem(std::string description) : description(description), solved(false){ - } //Destructor virtual ~Problem(){ - } //Gets virtual std::string getDescription() const{ diff --git a/Headers/Problem1.hpp b/Headers/Problem1.hpp index 8dd8123..8711836 100644 --- a/Headers/Problem1.hpp +++ b/Headers/Problem1.hpp @@ -38,7 +38,6 @@ private: static uint64_t MAX_NUMBER; //The highest number to be tested //Instance variables uint64_t fullSum; //For the sum of all the numbers - std::vector numbers; //Holds all the numbers public: //Constructor Problem1(); diff --git a/Headers/Problem10.hpp b/Headers/Problem10.hpp index 561a2b3..8635241 100644 --- a/Headers/Problem10.hpp +++ b/Headers/Problem10.hpp @@ -34,9 +34,9 @@ class Problem10 : public Problem{ private: //Variables //Static variables - static uint64_t GOAL_NUMBER; + static uint64_t GOAL_NUMBER; //The largest number to check for primes //Instance variables - uint64_t sum; + uint64_t sum; //The sum of all of the prime public: //Constructor Problem10(); diff --git a/Headers/Problem12.hpp b/Headers/Problem12.hpp index e4e8990..afd7468 100644 --- a/Headers/Problem12.hpp +++ b/Headers/Problem12.hpp @@ -36,8 +36,8 @@ private: //Static variables static uint64_t GOAL_DIVISORS; //The number of divisors that you want //Instance variables - int64_t sum; //The sum of the numbers up to counter - int64_t counter; //The next number to be added to sum + int64_t sum; //The sum of the numbers up to counter + int64_t counter; //The next number to be added to sum std::vector divisors; //Holds the divisors of the triangular number sum public: //Constructor diff --git a/Headers/Problem15.hpp b/Headers/Problem15.hpp index 41a087a..9fee0f0 100644 --- a/Headers/Problem15.hpp +++ b/Headers/Problem15.hpp @@ -42,7 +42,7 @@ private: //Functions //This function acts as a handler for moving the position on the grid and counting the distance //It moves right first, then down - void move(int currentX, int currentY, uint64_t& numOfRoutes); + void move(int currentX, int currentY); public: //Constructor Problem15(); diff --git a/Headers/Problem17.hpp b/Headers/Problem17.hpp index 9321a9d..f299763 100644 --- a/Headers/Problem17.hpp +++ b/Headers/Problem17.hpp @@ -34,7 +34,8 @@ class Problem17 : public Problem{ private: //Variables //Static variables - static int TOP_NUM; //This is the largest number to get the words of + static int START_NUM; //This is the smallest number to get the words of + static int STOP_NUM; //This is the largest number to get the words of //Instance variables uint64_t letterCount; //This is the cumulative number of letters in the words of the numbers diff --git a/Headers/Problem6.hpp b/Headers/Problem6.hpp index d5e7145..c971a40 100644 --- a/Headers/Problem6.hpp +++ b/Headers/Problem6.hpp @@ -42,7 +42,7 @@ private: public: //Constructor Problem6(); - //Operational functinos + //Operational functions virtual void solve(); //Solve the problem virtual void reset(); //Reset the problem so it can be run again //Gets diff --git a/Headers/Problem9.hpp b/Headers/Problem9.hpp index b00cd24..8c89b52 100644 --- a/Headers/Problem9.hpp +++ b/Headers/Problem9.hpp @@ -34,9 +34,9 @@ class Problem9 : public Problem{ private: //Variables //Instance variables - int a; //Holds the position on the first side - int b; //Holds the position on the second side - double c; //Holds the hyp + int a; //Holds the size of the first side + int b; //Holds the size of the second side + double c; //Holds the size of the hyp bool found; //A flag to determine if we have found the solution yet public: //Constructor diff --git a/Source/Problem1.cpp b/Source/Problem1.cpp index 1175586..52b3471 100644 --- a/Source/Problem1.cpp +++ b/Source/Problem1.cpp @@ -52,18 +52,13 @@ void Problem1::solve(){ for(uint64_t cnt = 1;cnt <= MAX_NUMBER;++cnt){ //If either 3 or 5 divides it evenly then add it to the vector if((cnt % 3) == 0){ - numbers.push_back(cnt); + fullSum += cnt; } else if((cnt % 5) == 0){ - numbers.push_back(cnt); + fullSum += cnt; } } - //Get the sum of all numbers - for(uint64_t num : numbers){ - fullSum += num; - } - //Stop the timer timer.stop(); @@ -75,7 +70,6 @@ void Problem1::solve(){ void Problem1::reset(){ Problem::reset(); fullSum = 0; - numbers.clear(); } diff --git a/Source/Problem10.cpp b/Source/Problem10.cpp index 3b4ccfb..ef6053e 100644 --- a/Source/Problem10.cpp +++ b/Source/Problem10.cpp @@ -31,6 +31,7 @@ #include "../Headers/Problem10.hpp" +//The largest number to check for primes uint64_t Problem10::GOAL_NUMBER = 2000000 - 1; //2,000,000 - 1 because is needs to be < instead of <= //Constructor @@ -56,7 +57,7 @@ void Problem10::solve(){ solved = true; } -//Reset the rpoblem so it can be run agian +//Reset the problem so it can be run again void Problem10::reset(){ Problem::reset(); sum = 0; diff --git a/Source/Problem13.cpp b/Source/Problem13.cpp index 4cd016c..fad5797 100644 --- a/Source/Problem13.cpp +++ b/Source/Problem13.cpp @@ -253,6 +253,7 @@ void Problem13::reserveVectors(){ //Constructor Problem13::Problem13() : Problem("Work out the first ten digits of the sum of the one-hundred 50-digit numbers"), sum(0){ reserveVectors(); + sum = 0; } //Solve the problem diff --git a/Source/Problem14.cpp b/Source/Problem14.cpp index dcf6766..d78abaf 100644 --- a/Source/Problem14.cpp +++ b/Source/Problem14.cpp @@ -36,7 +36,7 @@ Which starting number, under one million, produces the longest chain? //This is the top number that you will be checking against the series -uint64_t Problem14::MAX_NUM = 999999; +uint64_t Problem14::MAX_NUM = 1000000 - 1; //This function follows the rules of the sequence and returns its length uint64_t Problem14::checkSeries(uint64_t num){ diff --git a/Source/Problem15.cpp b/Source/Problem15.cpp index 387de2c..5fdbd12 100644 --- a/Source/Problem15.cpp +++ b/Source/Problem15.cpp @@ -35,7 +35,7 @@ int Problem15::LENGTH = 20; //The length of the grid //This function acts as a handler for moving the position on the grid and counting the distance //It moves right first, then down -void Problem15::move(int currentX, int currentY, uint64_t& numOfRoutes){ +void Problem15::move(int currentX, int currentY){ //Check if you are at the end if((currentX == WIDTH) && (currentY == LENGTH)){ ++numOfRoutes; @@ -44,12 +44,12 @@ void Problem15::move(int currentX, int currentY, uint64_t& numOfRoutes){ //Move right if possible if(currentX < WIDTH){ - move(currentX + 1, currentY, numOfRoutes); + move(currentX + 1, currentY); } //Move down if possible if(currentY < LENGTH){ - move(currentX, currentY + 1, numOfRoutes); + move(currentX, currentY + 1); } } @@ -73,7 +73,7 @@ void Problem15::solve(){ //We write this as a recursive function //When in a location it always moves right first, then down - move(currentX, currentY, numOfRoutes); + move(currentX, currentY); //Stop the timer timer.stop(); diff --git a/Source/Problem17.cpp b/Source/Problem17.cpp index 7b7f15f..341222a 100644 --- a/Source/Problem17.cpp +++ b/Source/Problem17.cpp @@ -31,7 +31,8 @@ //This is the largest number to get the words of -int Problem17::TOP_NUM = 1000; +int Problem17::START_NUM = 1; +int Problem17::STOP_NUM = 1000; //This function makes a word out of the number passed into it std::string Problem17::makeWord(int num){ @@ -186,7 +187,7 @@ void Problem17::solve(){ timer.start(); //Step through every element in nums and get the word representations of the numbers - for(int cnt = 1;cnt <= TOP_NUM;++cnt){ + for(int cnt = START_NUM;cnt <= STOP_NUM;++cnt){ std::string words = makeWord(cnt); //Get the words of each number in turn letterCount += countLetters(words); //Add the number of letters to the running tally } diff --git a/Source/Problem2.cpp b/Source/Problem2.cpp index 9b63131..3a8302b 100644 --- a/Source/Problem2.cpp +++ b/Source/Problem2.cpp @@ -32,7 +32,7 @@ //Holds the largest number that we are looking for -uint64_t Problem2::TOP_NUM = 4000000; +uint64_t Problem2::TOP_NUM = 4000000 - 1; //Constructor Problem2::Problem2() : Problem("What is the sum of the even Fibonacci numbers less than 4,000,000?"), fullSum(0){ diff --git a/Source/Problem31.cpp b/Source/Problem31.cpp index 0f7c715..5ab8dda 100644 --- a/Source/Problem31.cpp +++ b/Source/Problem31.cpp @@ -1,7 +1,7 @@ //ProjectEuler/ProjectEulerCPP/Source/Problem31.cpp //Matthew Ellison // Created: 06-19-20 -//Modified: 07-09-20 +//Modified: 07-11-20 //How many different ways can £2 be made using any number of coins? //Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/myClasses /* @@ -92,5 +92,9 @@ std::string Problem31::getString() const{ //Returns the number of correct permutations of the coins int Problem31::getPermutations() const{ + //If the problem hasn't been solved throw an exception + if(!solved){ + throw unsolved(); + } return permutations; } diff --git a/Source/Problem67.cpp b/Source/Problem67.cpp index 7539389..8003025 100644 --- a/Source/Problem67.cpp +++ b/Source/Problem67.cpp @@ -247,7 +247,7 @@ void Problem67::invert(){ } //Constructor -Problem67::Problem67() : Problem("Find the maximum total from the top to the bottom of the pyramid."){ +Problem67::Problem67() : Problem("Find the maximum total from the top to the bottom of the pyramid."), actualTotal(0){ } //Solve the problem