Updated comments and made sure style was consistent

This commit is contained in:
2020-07-10 13:36:16 -04:00
parent 7257a118d4
commit c72754dcf8
65 changed files with 1160 additions and 747 deletions

View File

@@ -1,7 +1,7 @@
//ProjectEuler/C++/Source/Problem11.cpp
//MatthewEllison
//ProjectEuler/ProjectEulerCPP/Source/Problem11.cpp
//Matthew Ellison
// Created: 09-29-18
//Modified: 07-14-19
//Modified: 07-09-20
//What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the 20×20 grid?
/*
08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08
@@ -27,7 +27,7 @@
*/
//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
@@ -53,6 +53,7 @@
#include "../Headers/Problem11.hpp"
//This is the grid of number that we will be working with
std::vector<int> Problem11::grid[20] = {{ 8, 02, 22, 97, 38, 15, 00, 40, 00, 75, 04, 05, 07, 78, 52, 12, 50, 77, 91, 8},
{49, 49, 99, 40, 17, 81, 18, 57, 60, 87, 17, 40, 98, 43, 69, 48, 04, 56, 62, 00},
{81, 49, 31, 73, 55, 79, 14, 29, 93, 71, 40, 67, 53, 88, 30, 03, 49, 13, 36, 65},
@@ -74,9 +75,11 @@ std::vector<int> Problem11::grid[20] = {{ 8, 02, 22, 97, 38, 15, 00, 40, 00, 75,
{20, 73, 35, 29, 78, 31, 90, 01, 74, 31, 49, 71, 48, 86, 81, 16, 23, 57, 05, 54},
{01, 70, 54, 71, 83, 51, 54, 69, 16, 92, 33, 48, 61, 43, 52, 01, 89, 19, 67, 48}};
//Constructor
Problem11::Problem11() : Problem("What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the 20x20 grid?"){
}
//Solve the problem
void Problem11::solve(){
//If the problem has already been solved do nothing and end the function
if(solved){
@@ -175,6 +178,13 @@ void Problem11::solve(){
solved = true;
}
//Reset the problem so it can be run again
void Problem11::reset(){
Problem::reset();
greatestProduct.clear();
}
//Return a string with the solution to the problem
std::string Problem11::getString() const{
//If the problem hasn't been solved throw an exception
if(!solved){
@@ -186,6 +196,7 @@ std::string Problem11::getString() const{
return results.str();
}
//Returns the numbers that were being searched
std::vector<int> Problem11::getNumbers() const{
//If the problem hasn't been solved throw an exception
if(!solved){
@@ -194,6 +205,7 @@ std::vector<int> Problem11::getNumbers() const{
return greatestProduct;
}
//Returns the product that was requested
int Problem11::getProduct() const{
//If the problem hasn't been solved throw an exception
if(!solved){
@@ -201,8 +213,3 @@ int Problem11::getProduct() const{
}
return mee::getProduct(greatestProduct);
}
void Problem11::reset(){
Problem::reset();
greatestProduct.clear();
}