Added a benchmark tool

This commit is contained in:
2020-07-08 20:38:37 -04:00
parent a7d960c3b1
commit 766af92f1a
68 changed files with 546 additions and 134 deletions

View File

@@ -7,7 +7,6 @@
#ifndef PROBLEM_HPP
#define PROBLEM_HPP
#include <string>
#include "Stopwatch.hpp"
@@ -35,8 +34,15 @@ public:
virtual std::string getTime(){
return timer.getStr();
}
virtual mee::Stopwatch getTimer(){
return timer;
}
virtual void solve() = 0;
virtual std::string getString() const = 0;
virtual void reset(){
timer.reset();
solved = false;
}
};
#endif //PROBLEM_HPP

View File

@@ -40,6 +40,7 @@ public:
Problem1();
virtual void solve();
virtual std::string getString() const;
virtual void reset();
//Returns the requested sum
uint64_t getSum() const;
};

View File

@@ -38,6 +38,7 @@ public:
Problem10();
virtual void solve();
virtual std::string getString() const;
virtual void reset();
//Returns the sum that was requested
uint64_t getSum() const;
};

View File

@@ -61,6 +61,7 @@ public:
Problem11();
virtual void solve();
virtual std::string getString() const;
virtual void reset();
//Returns the numbers that were being searched
std::vector<int> getNumbers() const;
//Returns the product that was requested

View File

@@ -40,6 +40,7 @@ public:
Problem12();
virtual void solve();
virtual std::string getString() const;
virtual void reset();
//Returns the triangular number
int64_t getTriangularNumber() const;
//Get the final number that was added to the triangular number

View File

@@ -140,13 +140,15 @@
class Problem13 : public Problem{
private:
//A vector to hold all of the numbers
static std::vector<mpz_class> nums;
std::vector<mpz_class> nums;
mpz_class sum;
void setNums();
void reserveVectors();
public:
Problem13();
virtual void solve();
virtual std::string getString() const;
virtual void reset();
//Returns the list 50-digit numbers
std::vector<mpz_class> getNumbers() const;
//Returns the sum of the 50-digit numbers

View File

@@ -46,6 +46,7 @@ public:
Problem14();
virtual void solve();
virtual std::string getString() const;
virtual void reset();
//Returns the length of the requested chain
uint64_t getLength() const;
//Returns the starting number of the requested chain

View File

@@ -42,6 +42,7 @@ public:
Problem15();
virtual void solve();
virtual std::string getString() const;
virtual void reset();
//Returns the number of routes found
uint64_t getNumberOfRoutes() const;
};

View File

@@ -43,6 +43,7 @@ public:
Problem16();
virtual void solve();
virtual std::string getString() const;
virtual void reset();
//Returns the number that was calculated
mpz_class getNumber() const;
//Return the sum of the digits of the number

View File

@@ -42,6 +42,7 @@ public:
Problem17();
virtual void solve();
virtual std::string getString() const;
virtual void reset();
//Returns the number of letters asked for
uint64_t getLetterCount() const;
};

View File

@@ -70,6 +70,7 @@ public:
Problem18();
virtual void solve();
virtual std::string getString() const;
virtual void reset();
//Returns the pyramid that was traversed as a string
std::string getPyramid();
//Returns the trail the algorithm took as a string

View File

@@ -58,6 +58,7 @@ public:
Problem19();
virtual void solve();
virtual std::string getString() const;
virtual void reset();
//Returns the total sundays that were asked for
uint64_t getTotalSundays() const;
};

View File

@@ -38,6 +38,7 @@ public:
Problem2();
virtual void solve();
virtual std::string getString() const;
virtual void reset();
//Returns the requested sum
uint64_t getSum() const;
};

View File

@@ -42,6 +42,7 @@ public:
Problem20();
virtual void solve();
virtual std::string getString() const;
virtual void reset();
//Returns the number 100!
mpz_class getNumber() const;
//Returns the number 100! in a string

View File

@@ -36,10 +36,12 @@ private:
static int LIMIT; //The top number that will be evaluated
std::vector<uint64_t> divisorSum; //Holds the sum of the divisors of the subscript number
std::vector<uint64_t> amicable; //Holds all amicable numbers
void reserveVectors();
public:
Problem21();
virtual void solve();
virtual std::string getString() const;
virtual void reset();
//Returns a vector with all of the amicable numbers calculated
std::vector<uint64_t> getAmicable() const;
//Returns the sum of all of the amicable numbers

View File

@@ -36,10 +36,12 @@ private:
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
static std::vector<std::string> names; //Holds the names that will be scored
void reserveVectors();
public:
Problem22();
virtual void solve();
virtual std::string getString() const;
virtual void reset();
//Returns the vector of the names being scored
std::vector<std::string> getNames() const;
//Returns the sum of the names scores

View File

@@ -38,10 +38,12 @@ private:
uint64_t sum; //The sum of all the numbers we are looking for
//A function that returns true if num can be created by adding two elements from abund and false if it cannot
bool isSum(const std::vector<int>& abund, int num);
void reserveVectors();
public:
Problem23();
virtual void solve();
virtual std::string getString() const;
virtual void reset();
//Returns the sum of the numbers asked for
uint64_t getSum() const;
};

View File

@@ -39,6 +39,7 @@ public:
Problem24();
virtual void solve();
virtual std::string getString() const;
virtual void reset();
//Returns a vector with all of the permutations
std::vector<std::string> getPermutationsList() const;
//Returns the specific permutations you are looking for

View File

@@ -42,6 +42,7 @@ public:
Problem25();
virtual void solve();
virtual std::string getString() const;
virtual void reset();
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

@@ -39,6 +39,7 @@ public:
Problem26();
virtual void solve();
virtual std::string getString() const;
virtual void reset();
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

@@ -41,6 +41,7 @@ public:
Problem27();
virtual void solve();
virtual std::string getString() const;
virtual void reset();
int64_t getTopA() const;
int64_t getTopB() const;
int64_t getTopN() const;

View File

@@ -36,12 +36,14 @@ class Problem28 : public Problem{
private:
std::vector<std::vector<int>> grid; //Holds the grid that we will be filling and searching
uint64_t sumOfDiagonals; //Holds the sum of the diagonals of the grid
void setupGrid(); //Sets up the grid
void setupGrid(); //This sets up the grid to hold the correct number of variables
void createGrid(); //Puts all of the numbers in the grid up the grid
void findSum(); //Finds the sum of the diagonals in the grid
public:
Problem28();
virtual void solve();
virtual std::string getString() const;
virtual void reset();
std::vector<std::vector<int>> getGrid() const; //Returns the grid
uint64_t getSum() const; //Returns the sum of the diagonals
};

View File

@@ -47,6 +47,7 @@ public:
Problem29();
virtual void solve();
virtual std::string getString() const;
virtual void reset();
unsigned int getBottomA() const;
unsigned int getTopA() const;
unsigned int getBottomB() const;

View File

@@ -39,6 +39,7 @@ public:
Problem3();
virtual void solve();
virtual std::string getString() const;
virtual void reset();
//Returns the list of factors of the number
std::vector<uint64_t> getFactors() const;
//Returns the largest factor of the number

View File

@@ -42,6 +42,7 @@ public:
Problem30();
virtual void solve();
virtual std::string getString() const;
virtual void reset();
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

@@ -38,6 +38,7 @@ public:
Problem31();
virtual void solve();
virtual std::string getString() const;
virtual void reset();
//Returns the number of correct permutations of the coins
int getPermutations() const;
};

View File

@@ -39,6 +39,7 @@ public:
Problem4();
virtual void solve();
virtual std::string getString() const;
virtual void reset();
//Returns the list of all palindromes
std::vector<uint64_t> getPalindromes() const;
//Returns the largest palindrome

View File

@@ -38,6 +38,7 @@ public:
Problem5();
virtual void solve();
virtual std::string getString() const;
virtual void reset();
//Returns the requested number
int getNumber() const;
};

View File

@@ -40,6 +40,7 @@ public:
Problem6();
virtual void solve();
virtual std::string getString() const;
virtual void reset();
//Returns the sum of all the squares
uint64_t getSumOfSquares() const;
//Returns the square of all of the sums

View File

@@ -143,8 +143,7 @@ private:
bool fromRight;
location(int x, int y, int t, bool r) : xLocation(x), yLocation(y), total(t), fromRight(r){ }
};
//This function takes every number in the vector and changes it to 100 - the number
void invert();
void invert(); //This function takes every number in the vector and changes it to 100 - the number
static const int NUM_ROWS = 100; //The number of rows in the list of numbers
std::list<location> foundPoints; //For the points that I have already found the shortest distance to
std::list<location> possiblePoints; //For the locations you are checking this round
@@ -155,6 +154,7 @@ public:
Problem67();
virtual void solve();
virtual std::string getString() const;
virtual void reset();
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

@@ -39,6 +39,7 @@ public:
Problem7();
virtual void solve();
virtual std::string getString() const;
virtual void reset();
//Returns the requested prime number
uint64_t getPrime() const;
};

View File

@@ -62,6 +62,7 @@ public:
Problem8();
virtual void solve();
virtual std::string getString() const;
virtual void reset();
//Returns the string of numbers that produces the largest product
std::string getLargestNums() const;
//Returns the requested product

View File

@@ -40,6 +40,7 @@ public:
Problem9();
virtual void solve();
virtual std::string getString() const;
virtual void reset();
//Returns the length of the first side
int getSideA() const;
//Returns the length of the second side