Changed Problem 67 to work with 18

This commit is contained in:
2020-07-25 16:02:49 -04:00
parent 3ed2de1dff
commit 44be9aa5b0
5 changed files with 147 additions and 334 deletions

View File

@@ -128,43 +128,18 @@ Find the maximum total from top to bottom
#define PROBLEM67_HPP
#include <vector>
#include <list>
#include <string>
#include "Problem.hpp"
#include "Problem18.hpp"
class Problem67 : public Problem{
class Problem67 : public Problem18{
//This class does exactly the same thing as 18, all we need to do is update the list that is searched through
private:
//Structures
struct location{
int xLocation;
int yLocation;
int total;
bool fromRight;
location(int x, int y, int t, bool r) : xLocation(x), yLocation(y), total(t), fromRight(r){ }
};
//Variables
//Static variables
static const int NUM_ROWS = 100; //The number of rows in the list of numbers
static std::vector<int> list[NUM_ROWS]; //This is the list you are trying to find a path through
//Instance variables
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
int actualTotal; //The true total of the path from the top to the bottom
//Functions
void invert(); //This function takes every number in the vector and changes it to 100 - the number
void setupList();
public:
//Constructor
Problem67();
//Operational functions
virtual void solve(); //Solve the problem
virtual void reset(); //Reset the problem so it can be run again
//Gets
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
Problem67() : Problem18(){
list.clear();
setupList();
}
};
/* Results: