diff --git a/Headers/Problems/Problem17.hpp b/Headers/Problems/Problem17.hpp index dde449b..7ab1da1 100644 --- a/Headers/Problems/Problem17.hpp +++ b/Headers/Problems/Problem17.hpp @@ -40,8 +40,7 @@ private: uint64_t letterCount; //This is the cumulative number of letters in the words of the numbers //Functions - std::string makeWord(int num); //This function makes a word out of the number passed into it - std::string wordHelper(int num); //This function helps makeWord() by returning the words for the numbers 1-9 + std::string makeWordFromNum(int number); //This function makes a word out of the number passed into it uint64_t countLetters(std::string str); //This counts the number of letters in the string that is passed in (ignoring numbers and punctuation) public: //Constructor diff --git a/Headers/Problems/Problem19.hpp b/Headers/Problems/Problem19.hpp index e10609e..9eb3a3e 100644 --- a/Headers/Problems/Problem19.hpp +++ b/Headers/Problems/Problem19.hpp @@ -67,7 +67,7 @@ public: }; /* Results There are 171 Sundays that landed on the first of the months from 1901 to 2000 -It took an average of 4.749 milliseconds to run this problem over 100 iterations +It took an average of 1.400 milliseconds to run this problem over 100 iterations */ #endif //PROBLEM19_HPP diff --git a/Headers/Problems/Problem22.hpp b/Headers/Problems/Problem22.hpp index fc22d73..dd31a0b 100644 --- a/Headers/Problems/Problem22.hpp +++ b/Headers/Problems/Problem22.hpp @@ -39,6 +39,7 @@ private: //Instance variables std::vector sums; //Holds the score based on the sum of the characters in the name std::vector prod; //Holds the score based on the sum of the characters and the location in alphabetical order + uint64_t sum; //Holds the sum of the scores //Functions void reserveVectors(); //Reserve the size of the vector to speed up insertion diff --git a/Headers/Problems/Problem9.hpp b/Headers/Problems/Problem9.hpp index ec3132d..cb26f62 100644 --- a/Headers/Problems/Problem9.hpp +++ b/Headers/Problems/Problem9.hpp @@ -33,6 +33,8 @@ class Problem9 : public Problem{ private: //Variables + //Static variables + static int GOAL_SUM; //a + b + c should equal this number //Instance variables int a; //Holds the size of the first side int b; //Holds the size of the second side diff --git a/src/Problems/Problem1.cpp b/src/Problems/Problem1.cpp index c76fd3f..33af4a5 100644 --- a/src/Problems/Problem1.cpp +++ b/src/Problems/Problem1.cpp @@ -26,7 +26,6 @@ #include #include #include -#include "Stopwatch.hpp" #include "Problems/Problem1.hpp" diff --git a/src/Problems/Problem10.cpp b/src/Problems/Problem10.cpp index 762dd6a..f5f5534 100644 --- a/src/Problems/Problem10.cpp +++ b/src/Problems/Problem10.cpp @@ -25,7 +25,6 @@ #include #include #include -#include "Stopwatch.hpp" #include "Algorithms.hpp" #include "Problems/Problem10.hpp" diff --git a/src/Problems/Problem11.cpp b/src/Problems/Problem11.cpp index a36b546..f89fbff 100644 --- a/src/Problems/Problem11.cpp +++ b/src/Problems/Problem11.cpp @@ -47,7 +47,6 @@ #include #include #include -#include "Stopwatch.hpp" #include "Algorithms.hpp" #include "Problems/Problem11.hpp" diff --git a/src/Problems/Problem12.cpp b/src/Problems/Problem12.cpp index a69d4fc..c38e446 100644 --- a/src/Problems/Problem12.cpp +++ b/src/Problems/Problem12.cpp @@ -24,7 +24,6 @@ #include #include #include -#include "Stopwatch.hpp" #include "Algorithms.hpp" #include "Problems/Problem12.hpp" diff --git a/src/Problems/Problem13.cpp b/src/Problems/Problem13.cpp index 68bc6c2..7504acb 100644 --- a/src/Problems/Problem13.cpp +++ b/src/Problems/Problem13.cpp @@ -132,7 +132,6 @@ #include #include #include "gmpxx.h" //This is part of the gmp library -#include "Stopwatch.hpp" #include "Algorithms.hpp" #include "Problems/Problem13.hpp" diff --git a/src/Problems/Problem14.cpp b/src/Problems/Problem14.cpp index a70ea9a..f58fc97 100644 --- a/src/Problems/Problem14.cpp +++ b/src/Problems/Problem14.cpp @@ -30,7 +30,6 @@ Which starting number, under one million, produces the longest chain? #include #include #include -#include "Stopwatch.hpp" #include "Problems/Problem14.hpp" diff --git a/src/Problems/Problem15.cpp b/src/Problems/Problem15.cpp index ef1b369..3682e62 100644 --- a/src/Problems/Problem15.cpp +++ b/src/Problems/Problem15.cpp @@ -25,7 +25,6 @@ #include #include #include -#include "Stopwatch.hpp" #include "Problems/Problem15.hpp" diff --git a/src/Problems/Problem16.cpp b/src/Problems/Problem16.cpp index be01978..aa971e2 100644 --- a/src/Problems/Problem16.cpp +++ b/src/Problems/Problem16.cpp @@ -27,7 +27,6 @@ #include #include #include -#include "Stopwatch.hpp" #include "Problems/Problem16.hpp" diff --git a/src/Problems/Problem18.cpp b/src/Problems/Problem18.cpp index c67564d..2757374 100644 --- a/src/Problems/Problem18.cpp +++ b/src/Problems/Problem18.cpp @@ -44,7 +44,6 @@ #include #include #include -#include "Stopwatch.hpp" #include "Problems/Problem18.hpp" diff --git a/src/Problems/Problem2.cpp b/src/Problems/Problem2.cpp index 8e5c3e7..3dc5290 100644 --- a/src/Problems/Problem2.cpp +++ b/src/Problems/Problem2.cpp @@ -25,7 +25,6 @@ #include #include #include -#include "Stopwatch.hpp" #include "Algorithms.hpp" #include "Problems/Problem2.hpp" diff --git a/src/Problems/Problem20.cpp b/src/Problems/Problem20.cpp index 42cbc30..d72b73d 100644 --- a/src/Problems/Problem20.cpp +++ b/src/Problems/Problem20.cpp @@ -29,7 +29,6 @@ #include #include #include "gmpxx.h" -#include "Stopwatch.hpp" #include "Problems/Problem20.hpp" diff --git a/src/Problems/Problem21.cpp b/src/Problems/Problem21.cpp index e3f8360..670e0ae 100644 --- a/src/Problems/Problem21.cpp +++ b/src/Problems/Problem21.cpp @@ -27,7 +27,6 @@ #include #include #include "Algorithms.hpp" -#include "Stopwatch.hpp" #include "Problems/Problem21.hpp" diff --git a/src/Problems/Problem22.cpp b/src/Problems/Problem22.cpp index c3afc29..674a5d6 100644 --- a/src/Problems/Problem22.cpp +++ b/src/Problems/Problem22.cpp @@ -27,7 +27,6 @@ #include #include #include -#include "Stopwatch.hpp" #include "Algorithms.hpp" #include "Problems/Problem22.hpp" @@ -442,6 +441,8 @@ void Problem22::solve(){ prod.at(cnt) = sums.at(cnt) * (cnt + 1); } + sum = mee::getSum(prod); + //Stop the timer timer.stop(); @@ -464,7 +465,7 @@ std::string Problem22::getResult(){ throw Unsolved(); } std::stringstream result; - result << "The answer to the question is " << mee::getSum(prod); + result << "The answer to the question is " << sum; return result.str(); } //Returns the vector of the names being scored diff --git a/src/Problems/Problem23.cpp b/src/Problems/Problem23.cpp index 6059146..538d4e6 100644 --- a/src/Problems/Problem23.cpp +++ b/src/Problems/Problem23.cpp @@ -27,7 +27,6 @@ #include #include #include -#include "Stopwatch.hpp" #include "Algorithms.hpp" #include "Problems/Problem23.hpp" diff --git a/src/Problems/Problem24.cpp b/src/Problems/Problem24.cpp index 5261443..8c2c7bc 100644 --- a/src/Problems/Problem24.cpp +++ b/src/Problems/Problem24.cpp @@ -26,7 +26,6 @@ #include #include #include "Algorithms.hpp" -#include "Stopwatch.hpp" #include "Problems/Problem24.hpp" diff --git a/src/Problems/Problem25.cpp b/src/Problems/Problem25.cpp index 8cb86ac..d5dc3e1 100644 --- a/src/Problems/Problem25.cpp +++ b/src/Problems/Problem25.cpp @@ -29,7 +29,6 @@ #include #include "gmpxx.h" #include "Algorithms.hpp" -#include "Stopwatch.hpp" #include "Problems/Problem25.hpp" diff --git a/src/Problems/Problem3.cpp b/src/Problems/Problem3.cpp index e9767d6..b833432 100644 --- a/src/Problems/Problem3.cpp +++ b/src/Problems/Problem3.cpp @@ -26,7 +26,6 @@ #include #include #include -#include "Stopwatch.hpp" #include "Algorithms.hpp" #include "Problems/Problem3.hpp" diff --git a/src/Problems/Problem4.cpp b/src/Problems/Problem4.cpp index cc062f6..b20ac4e 100644 --- a/src/Problems/Problem4.cpp +++ b/src/Problems/Problem4.cpp @@ -26,7 +26,6 @@ #include #include #include -#include "Stopwatch.hpp" #include "Problems/Problem4.hpp" diff --git a/src/Problems/Problem5.cpp b/src/Problems/Problem5.cpp index 42d6fa4..7885ff4 100644 --- a/src/Problems/Problem5.cpp +++ b/src/Problems/Problem5.cpp @@ -26,7 +26,6 @@ #include #include #include -#include "Stopwatch.hpp" #include "Problems/Problem5.hpp" diff --git a/src/Problems/Problem6.cpp b/src/Problems/Problem6.cpp index d44d537..469b2a3 100644 --- a/src/Problems/Problem6.cpp +++ b/src/Problems/Problem6.cpp @@ -26,7 +26,6 @@ #include #include #include -#include "Stopwatch.hpp" #include "Problems/Problem6.hpp" diff --git a/src/Problems/Problem7.cpp b/src/Problems/Problem7.cpp index e190115..0d104d9 100644 --- a/src/Problems/Problem7.cpp +++ b/src/Problems/Problem7.cpp @@ -26,7 +26,6 @@ #include #include #include -#include "Stopwatch.hpp" #include "Algorithms.hpp" #include "Problems/Problem7.hpp" diff --git a/src/Problems/Problem8.cpp b/src/Problems/Problem8.cpp index cbe0154..8ac7a93 100644 --- a/src/Problems/Problem8.cpp +++ b/src/Problems/Problem8.cpp @@ -48,7 +48,6 @@ #include #include #include -#include "Stopwatch.hpp" #include "Problems/Problem8.hpp" diff --git a/src/Problems/Problem9.cpp b/src/Problems/Problem9.cpp index 4d9e976..c7abb7e 100644 --- a/src/Problems/Problem9.cpp +++ b/src/Problems/Problem9.cpp @@ -25,10 +25,12 @@ #include #include #include -#include "Stopwatch.hpp" #include "Problems/Problem9.hpp" +//a + b + c should equal this number +int Problem9::GOAL_SUM = 1000; + //Constructor Problem9::Problem9() : Problem("There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product of abc."), a(1), b(0), c(0), found(false){ } @@ -43,18 +45,18 @@ void Problem9::solve(){ timer.start(); //Loop through all possible a's - while((a < 1000) && !found){ + while((a < GOAL_SUM) && !found){ b = a + 1; //b bust be greater than a c = sqrt((a * a) + (b * b)); //Loop through all possible b's - while((a + b + c) < 1000){ + while((a + b + c) < GOAL_SUM){ ++b; c = sqrt((a * a) + (b * b)); } //If the sum == 1000 you found the number, otherwise go to the next possible a - if((a + b + c) == 1000){ + if((a + b + c) == GOAL_SUM){ found = true; } else{ @@ -70,7 +72,7 @@ void Problem9::solve(){ solved = true; } else{ - //TODO: Throw an exception + throw Unsolved("The triplet was not found!"); } //Throw a flag to show the problem is solved