Updated how results are retrieved

This commit is contained in:
2020-07-20 00:53:08 -04:00
parent 22871b71e9
commit 2616dabe6d
67 changed files with 132 additions and 434 deletions

View File

@@ -24,6 +24,7 @@
#ifndef PROBLEM_HPP
#define PROBLEM_HPP
#include <sstream>
#include <string>
#include "Stopwatch.hpp"
@@ -34,6 +35,7 @@ protected:
mee::Stopwatch timer; //Used to determine your algorithm's run time
bool solved; //Holds true after the problem has been solved
class Unsolved{}; //An exception class thrown if you try to access something before it has been solved
std::stringstream result; //Get the result of the problem
public:
//Constructors
Problem() : solved(false){
@@ -47,6 +49,7 @@ public:
virtual std::string getDescription() const{
return description;
}
//Get the time it took to run the algorithm as a string
virtual std::string getTime(){
//If the problem hasn't been solved throw an exception
if(!solved){
@@ -54,6 +57,7 @@ public:
}
return timer.getStr();
}
//Get a copy of the timer that was used to time the algorithm
virtual mee::Stopwatch getTimer(){
//If the problem hasn't been solved throw an exception
if(!solved){
@@ -63,12 +67,20 @@ public:
}
//Reset the problem so it can be run again
virtual void reset(){
result.str(std::string());
timer.reset();
solved = false;
}
//Return a string with the solution to the problem
virtual std::string getResults(){
//If the problem hasn't been solved throw an exception
if(!solved){
throw Unsolved();
}
return result.str();
}
//Pure virtual functions
virtual void solve() = 0; //Solve the problem
virtual std::string getString() const = 0; //Return a string with the solution to the problem
};
#endif //PROBLEM_HPP

View File

@@ -45,7 +45,6 @@ public:
virtual void solve(); //Solve the problem
virtual void reset(); //Reset the problem so it can be run again
//Gets
virtual std::string getString() const; //Return a string with the solution to the problem
uint64_t getSum() const; //Returns the requested sum
};

View File

@@ -44,7 +44,6 @@ public:
virtual void solve(); //Solve the problem
virtual void reset(); //Reset the problem so it can be run again
//Gets
virtual std::string getString() const; //Return a string with the solution to the problem
uint64_t getSum() const; //Returns the sum that was requested
};

View File

@@ -66,7 +66,6 @@ public:
virtual void solve(); //Solve the problem
virtual void reset(); //Reset the problem so it can be run again
//Gets
virtual std::string getString() const; //Return a string with the solution to the problem
std::vector<int> getNumbers() const; //Returns the numbers that were being searched
int getProduct() const; //Returns the product that was requested
};

View File

@@ -46,7 +46,6 @@ public:
virtual void solve(); //Solve the problem
virtual void reset(); //Reset the problem so it can be run again
//Gets
virtual std::string getString() const; //Return a string with the solution to the problem
int64_t getTriangularNumber() const; //Returns the triangular number
int64_t getLastNumberAdded() const; //Get the final number that was added to the triangular number
std::vector<int64_t> getDivisorsOfTriangularNumber() const; //Returns the list of divisors of the requested number

View File

@@ -154,7 +154,6 @@ public:
virtual void solve(); //Solve the problem
virtual void reset(); //Reset the problem so it can be run again
//Gets
virtual std::string getString() const; //Return a string with the solution to the problem
std::vector<mpz_class> getNumbers() const; //Returns the list 50-digit numbers
mpz_class getSum() const; //Returns the sum of the 50-digit numbers
};

View File

@@ -53,7 +53,6 @@ public:
virtual void solve(); //Solve the problem
virtual void reset(); //Reset the problem so it can be run again
//Gets
virtual std::string getString() const; //Return a string with the solution to the problem
uint64_t getLength() const; //Returns the length of the requested chain
uint64_t getStartingNumber() const; //Returns the starting number of the requested chain
};

View File

@@ -50,7 +50,6 @@ public:
virtual void solve(); //Solve the problem
virtual void reset(); //Reset the problem so it can be run again
//Gets
virtual std::string getString() const; //Return a string with the solution to the problem
uint64_t getNumberOfRoutes() const; //Returns the number of routes found
};
/* Results:

View File

@@ -49,7 +49,6 @@ public:
virtual void solve(); //Solve the problem
virtual void reset(); //Reset the problem so it can be run again
//Gets
virtual std::string getString() const; //Return a string with the solution to the problem
mpz_class getNumber() const; //Returns the number that was calculated
int getSum() const; //Return the sum of the digits of the number
};

View File

@@ -50,7 +50,6 @@ public:
virtual void solve(); //Solve the problem
virtual void reset(); //Reset the problem so it can be run again
//Gets
virtual std::string getString() const; //Return a string with the solution to the problem
uint64_t getLetterCount() const; //Returns the number of letters asked for
};
/* Results:

View File

@@ -79,7 +79,6 @@ public:
virtual void solve(); //Solve the problem
virtual void reset(); //Reset the problem so it can be run again
//Gets
virtual std::string getString() const; //Return a string with the solution to the problem
std::string getPyramid(); //Returns the pyramid that was traversed as a string
std::string getTrail(); //Returns the trail the algorithm took as a string
int getTotal() const; //Returns the total that was asked for

View File

@@ -62,7 +62,6 @@ public:
virtual void solve(); //Solve the problem
virtual void reset(); //Reset the problem so it can be run again
//Gets
virtual std::string getString() const; //Return a string with the solution to the problem
uint64_t getTotalSundays() const; //Returns the total sundays that were asked for
};
/* Results

View File

@@ -44,7 +44,6 @@ public:
virtual void solve(); //Solve the problem
virtual void reset(); //Reset the problem so it can be run again
//Gets
virtual std::string getString() const; //Return a string with the solution to the problem
uint64_t getSum() const; //Returns the requested sum
};

View File

@@ -47,7 +47,6 @@ public:
virtual void solve(); //Solve the problem
virtual void reset(); //Reset the problem so it can be run again
//Gets
virtual std::string getString() const; //Return a string with the solution to the problem
mpz_class getNumber() const; //Returns the number 100!
std::string getNumberString() const; //Returns the number 100! in a string
uint64_t getSum() const; //Returns the sum of the digits of 100!

View File

@@ -49,7 +49,6 @@ public:
virtual void solve(); //Solve the problem
virtual void reset(); //Reset the problem so it can be run again
//Gets
virtual std::string getString() const; //Return a string with the solution to the problem
std::vector<uint64_t> getAmicable() const; //Returns a vector with all of the amicable numbers calculated
uint64_t getSum() const; //Returns the sum of all of the amicable numbers
};

View File

@@ -49,7 +49,6 @@ public:
virtual void solve(); //Solve the problem
virtual void reset(); //Reset the problem so it can be run again
//Gets
virtual std::string getString() const; //Return a string with the solution to the problem
std::vector<std::string> getNames() const; //Returns the vector of the names being scored
uint64_t getNameScoreSum() const; //Returns the sum of the names scores
};

View File

@@ -50,7 +50,6 @@ public:
virtual void solve(); //Solve the problem
virtual void reset(); //Reset the problem so it can be run again
//Gets
virtual std::string getString() const; //Return a string with the solution to the problem
uint64_t getSum() const; //Returns the sum of the numbers asked for
};

View File

@@ -44,7 +44,6 @@ public:
virtual void solve(); //Solve the problem
virtual void reset(); //Reset the problem so it can be run again
//Gets
virtual std::string getString() const; //Return a string with the solution to the problem
std::vector<std::string> getPermutationsList() const; //Returns a vector with all of the permutations
std::string getPermutation() const; //Returns the specific permutations you are looking for
};

View File

@@ -48,7 +48,6 @@ public:
virtual void solve(); //Solve the problem
virtual void reset(); //Reset the problem so it can be run again
//Gets
virtual std::string getString() const; //Return a string with the solution to the problem
mpz_class getNumber() const; //Returns the Fibonacci number asked for
std::string getNumberString() const; //Returns the Fibonacci number asked for as a string
mpz_class getIndex() const; //Returns the index of the requested Fibonacci number

View File

@@ -45,7 +45,6 @@ public:
virtual void solve(); //Solve the problem
virtual void reset(); //Reset the problem so it can be run again
//Gets
virtual std::string getString() const; //Return a string with the solution to the problem
unsigned int getLongestCycle() const; //Returns the length of the longest cycle
unsigned int getLongestNumber() const; //Returns the denominator that starts the longest cycle
};

View File

@@ -46,7 +46,6 @@ public:
virtual void solve(); //Solve the problem
virtual void reset(); //Reset the problem so it can be run again
//Gets
virtual std::string getString() const; //Return a string with the solution to the problem
int64_t getTopA() const; //Returns the top A that was generated
int64_t getTopB() const; //Returns the top B that was generated
int64_t getTopN() const; //Returns the top N that was generated

View File

@@ -50,7 +50,6 @@ public:
virtual void solve(); //Solve the problem
virtual void reset(); //Reset the problem so it can be run again
//Gets
virtual std::string getString() const; //Return a string with the solution to the problem
std::vector<std::vector<int>> getGrid() const; //Returns the grid
uint64_t getSum() const; //Returns the sum of the diagonals
};

View File

@@ -53,7 +53,6 @@ public:
virtual void solve(); //Solve the problem
virtual void reset(); //Reset the problem so it can be run again
//Gets
virtual std::string getString() const; //Return a string with the solution to the problem
unsigned int getBottomA() const; //Returns the lowest possible value for a
unsigned int getTopA() const; //Returns the highest possible value for a
unsigned int getBottomB() const; //Returns the lowest possible value for b

View File

@@ -45,7 +45,6 @@ public:
virtual void solve(); //Solve the problem
virtual void reset(); //Reset the problem so it can be run again
//Gets
virtual std::string getString() const; //Return a string with the solution to the problem
std::vector<uint64_t> getFactors() const; //Returns the list of factors of the number
uint64_t getLargestFactor() const; //Returns the largest factor of the number
uint64_t getGoalNumber() const; //Returns the number

View File

@@ -50,7 +50,6 @@ public:
virtual void solve(); //Solve the problem
virtual void reset(); //Reset the problem so it can be run again
//Gets
virtual std::string getString() const; //Return a string with the solution to the problem
uint64_t getTopNum() const; //This returns the top number to be checked
std::vector<uint64_t> getListOfSumOfFifths() const; //This returns a copy of the vector holding all the numbers that are the sum of the fifth power of their digits
uint64_t getSumOfList() const; //This returns the sum of all entries in sumOfFifthNumbers

View File

@@ -44,7 +44,6 @@ public:
virtual void solve(); //Solve the problem
virtual void reset(); //Reset the problem so it can be run again
//Gets
virtual std::string getString() const; //Return a string with the solution to the problem
int getPermutations() const; //Returns the number of correct permutations of the coins
};

View File

@@ -45,7 +45,6 @@ public:
virtual void solve(); //Solve the problem
virtual void reset(); //Reset the problem so it can be run again
//Gets
virtual std::string getString() const; //Return a string with the solution to the problem
std::vector<uint64_t> getPalindromes() const; //Returns the list of all palindromes
uint64_t getLargestPalindrome() const; //Returns the largest palindrome
};

View File

@@ -43,7 +43,6 @@ public:
virtual void solve(); //Solve the problem
virtual void reset(); //Reset the problem so it can be run again
//Gets
virtual std::string getString() const; //Return a string with the solution to the problem
int getNumber() const; //Returns the requested number
};

View File

@@ -46,7 +46,6 @@ public:
virtual void solve(); //Solve the problem
virtual void reset(); //Reset the problem so it can be run again
//Gets
virtual std::string getString() const; //Return a string with the solution to the problem
uint64_t getSumOfSquares() const; //Returns the sum of all the squares
uint64_t getSquareOfSum() const; //Returns the square of all of the sums
uint64_t getDifference() const; //Returns the requested difference

View File

@@ -162,7 +162,6 @@ public:
virtual void solve(); //Solve the problem
virtual void reset(); //Reset the problem so it can be run again
//Gets
virtual std::string getString() const; //Return a string with the solution to the problem
std::string getPyramid() const; //Returns the pyramid that was traversed as a string
std::string getTrail(); //Returns the trail the algorithm took as a string
int getTotal() const; //Returns the total that was asked for

View File

@@ -45,7 +45,6 @@ public:
virtual void solve(); //Solve the problem
virtual void reset(); //Reset the problem so it can be run again
//Gets
virtual std::string getString() const; //Return a string with the solution to the problem
uint64_t getPrime() const; //Returns the requested prime number
};

View File

@@ -68,7 +68,6 @@ public:
virtual void solve(); //Solve the problem
virtual void reset(); //Reset the problem so it can be run again
//Gets
virtual std::string getString() const; //Return a string with the solution to the problem
std::string getLargestNums() const; //Returns the string of numbers that produces the largest product
uint64_t getLargestProduct() const; //Returns the requested product
};

View File

@@ -45,7 +45,6 @@ public:
virtual void solve(); //Solve the problem
virtual void reset(); //Reset the problem so it can be run again
//Gets
virtual std::string getString() const; //Return a string with the solution to the problem
int getSideA() const; //Returns the length of the first side
int getSideB() const; //Returns the length of the second side
int getSideC() const; //Returns the length of the hyp