mirror of
https://bitbucket.org/Mattrixwv/projecteulercpp.git
synced 2025-12-06 17:13:59 -05:00
Removed unnecessary headers
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -39,6 +39,7 @@ private:
|
||||
//Instance variables
|
||||
std::vector<uint64_t> sums; //Holds the score based on the sum of the characters in the name
|
||||
std::vector<uint64_t> 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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#include <sstream>
|
||||
#include <cinttypes>
|
||||
#include <vector>
|
||||
#include "Stopwatch.hpp"
|
||||
#include "Problems/Problem1.hpp"
|
||||
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include "Stopwatch.hpp"
|
||||
#include "Algorithms.hpp"
|
||||
#include "Problems/Problem10.hpp"
|
||||
|
||||
|
||||
@@ -47,7 +47,6 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include "Stopwatch.hpp"
|
||||
#include "Algorithms.hpp"
|
||||
#include "Problems/Problem11.hpp"
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include "Stopwatch.hpp"
|
||||
#include "Algorithms.hpp"
|
||||
#include "Problems/Problem12.hpp"
|
||||
|
||||
|
||||
@@ -132,7 +132,6 @@
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include "gmpxx.h" //This is part of the gmp library
|
||||
#include "Stopwatch.hpp"
|
||||
#include "Algorithms.hpp"
|
||||
#include "Problems/Problem13.hpp"
|
||||
|
||||
|
||||
@@ -30,7 +30,6 @@ Which starting number, under one million, produces the longest chain?
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include "Stopwatch.hpp"
|
||||
#include "Problems/Problem14.hpp"
|
||||
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include "Stopwatch.hpp"
|
||||
#include "Problems/Problem15.hpp"
|
||||
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <gmpxx.h>
|
||||
#include "Stopwatch.hpp"
|
||||
#include "Problems/Problem16.hpp"
|
||||
|
||||
|
||||
|
||||
@@ -44,7 +44,6 @@
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include "Stopwatch.hpp"
|
||||
#include "Problems/Problem18.hpp"
|
||||
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include "Stopwatch.hpp"
|
||||
#include "Algorithms.hpp"
|
||||
#include "Problems/Problem2.hpp"
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include "gmpxx.h"
|
||||
#include "Stopwatch.hpp"
|
||||
#include "Problems/Problem20.hpp"
|
||||
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include "Algorithms.hpp"
|
||||
#include "Stopwatch.hpp"
|
||||
#include "Problems/Problem21.hpp"
|
||||
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
#include <cinttypes>
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#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
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include "Stopwatch.hpp"
|
||||
#include "Algorithms.hpp"
|
||||
#include "Problems/Problem23.hpp"
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
#include "Algorithms.hpp"
|
||||
#include "Stopwatch.hpp"
|
||||
#include "Problems/Problem24.hpp"
|
||||
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
#include <sstream>
|
||||
#include "gmpxx.h"
|
||||
#include "Algorithms.hpp"
|
||||
#include "Stopwatch.hpp"
|
||||
#include "Problems/Problem25.hpp"
|
||||
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include "Stopwatch.hpp"
|
||||
#include "Algorithms.hpp"
|
||||
#include "Problems/Problem3.hpp"
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include "Stopwatch.hpp"
|
||||
#include "Problems/Problem4.hpp"
|
||||
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include "Stopwatch.hpp"
|
||||
#include "Problems/Problem5.hpp"
|
||||
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include "Stopwatch.hpp"
|
||||
#include "Problems/Problem6.hpp"
|
||||
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include "Stopwatch.hpp"
|
||||
#include "Algorithms.hpp"
|
||||
#include "Problems/Problem7.hpp"
|
||||
|
||||
|
||||
@@ -48,7 +48,6 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
#include "Stopwatch.hpp"
|
||||
#include "Problems/Problem8.hpp"
|
||||
|
||||
|
||||
|
||||
@@ -25,10 +25,12 @@
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#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
|
||||
|
||||
Reference in New Issue
Block a user