mirror of
https://bitbucket.org/Mattrixwv/projecteulercpp.git
synced 2025-12-06 17:13:59 -05:00
Updated comments and made sure style was consistent
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
//ProjectEuler/C++/Source/Problem18.hpp
|
||||
//ProjectEuler/ProjectEulerCPP/Source/Problem18.hpp
|
||||
//Matthew Ellison
|
||||
// Created: 11-01-18
|
||||
//Modified: 07-14-19
|
||||
//Modified: 07-09-20
|
||||
//Find the maximum total from top to bottom
|
||||
/*
|
||||
75
|
||||
@@ -23,7 +23,7 @@
|
||||
//This is done using a breadth first search
|
||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/myClasses
|
||||
/*
|
||||
Copyright (C) 2019 Matthew Ellison
|
||||
Copyright (C) 2020 Matthew Ellison
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
@@ -48,6 +48,7 @@
|
||||
#include "../Headers/Problem18.hpp"
|
||||
|
||||
|
||||
//Setup the list you are trying to find a path through
|
||||
std::vector<int> Problem18::list[NUM_ROWS] =
|
||||
{{75},
|
||||
{95, 64},
|
||||
@@ -65,9 +66,7 @@ std::vector<int> Problem18::list[NUM_ROWS] =
|
||||
{63, 66, 04, 68, 89, 53, 67, 30, 73, 16, 69, 87, 40, 31},
|
||||
{04, 62, 98, 27, 23, 9, 70, 98, 73, 93, 38, 53, 60, 04, 23}};
|
||||
|
||||
Problem18::Problem18() : Problem("Find the maximum total from the top to the bottom of the pyramid."), actualTotal(0){
|
||||
}
|
||||
|
||||
//This list turns every number in the vector into 100 - num
|
||||
void Problem18::invert(){
|
||||
for(unsigned int rowCnt = 0;rowCnt < NUM_ROWS;++rowCnt){
|
||||
for(unsigned int colCnt = 0;colCnt < list[rowCnt].size();++colCnt){
|
||||
@@ -76,6 +75,11 @@ void Problem18::invert(){
|
||||
}
|
||||
}
|
||||
|
||||
//Constructor
|
||||
Problem18::Problem18() : Problem("Find the maximum total from the top to the bottom of the pyramid."), actualTotal(0){
|
||||
}
|
||||
|
||||
//Solve the problem
|
||||
void Problem18::solve(){
|
||||
//If the problem has already been solved do nothing and end the function
|
||||
if(solved){
|
||||
@@ -135,6 +139,15 @@ void Problem18::solve(){
|
||||
solved = true;
|
||||
}
|
||||
|
||||
//Reset the problem so it can be run again
|
||||
void Problem18::reset(){
|
||||
Problem::reset();
|
||||
foundPoints.clear();
|
||||
possiblePoints.clear();
|
||||
actualTotal = 0;
|
||||
}
|
||||
|
||||
//Return a string with the solution to the problem
|
||||
std::string Problem18::getString() const{
|
||||
//If the problem hasn't been solved throw an exception
|
||||
if(!solved){
|
||||
@@ -146,6 +159,7 @@ std::string Problem18::getString() const{
|
||||
return results.str();
|
||||
}
|
||||
|
||||
//Returns the pyramid that was traversed as a string
|
||||
std::string Problem18::getPyramid(){
|
||||
//If the problem hasn't been solved throw an exception
|
||||
if(!solved){
|
||||
@@ -162,6 +176,7 @@ std::string Problem18::getPyramid(){
|
||||
return results.str();
|
||||
}
|
||||
|
||||
//Returns the trail the algorithm took as a string
|
||||
std::string Problem18::getTrail(){
|
||||
//If the problem hasn't been solved throw an exception
|
||||
if(!solved){
|
||||
@@ -218,6 +233,7 @@ std::string Problem18::getTrail(){
|
||||
return results.str();
|
||||
}
|
||||
|
||||
//Returns the total that was asked for
|
||||
int Problem18::getTotal() const{
|
||||
//If the problem hasn't been solved throw an exception
|
||||
if(!solved){
|
||||
@@ -225,10 +241,3 @@ int Problem18::getTotal() const{
|
||||
}
|
||||
return actualTotal;
|
||||
}
|
||||
|
||||
void Problem18::reset(){
|
||||
Problem::reset();
|
||||
foundPoints.clear();
|
||||
possiblePoints.clear();
|
||||
actualTotal = 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user