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,11 +1,11 @@
//ProjectEuler/C++/Source/Problem28.cpp
//ProjectEuler/ProjectEulerCPP/Source/Problem28.cpp
//Matthew Ellison
// Created: 09-21-19
//Modified: 09-21-19
//Modified: 07-09-20
//What is the sum of the numbers on the diagonals in a 1001 by 1001 spiral formed by starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral
//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
@@ -29,10 +29,7 @@
#include "../Headers/Problem28.hpp"
Problem28::Problem28() : Problem("What is the sum of the number on the diagonals in a 1001 x 1001 spiral formed by starting with the number 1 and moving to the right in a clockwise direction?"){
setupGrid();
sumOfDiagonals = 0;
}
//This sets up the grid to hold the correct number of variables
void Problem28::setupGrid(){
//Set the size of the grid to 1001 x 1001
for(int cnt = 0;cnt < 1001;++cnt){
@@ -43,7 +40,7 @@ void Problem28::setupGrid(){
}
}
//Sets up the grid
//Puts all of the numbers in the grid up the grid
void Problem28::createGrid(){
bool finalLocation = false; //A flag to indicate if the final location to be filled has been reached
//Set the number that is going to be put at each location
@@ -109,6 +106,13 @@ void Problem28::findSum(){
}
}
//Constructor
Problem28::Problem28() : Problem("What is the sum of the number on the diagonals in a 1001 x 1001 spiral formed by starting with the number 1 and moving to the right in a clockwise direction?"){
setupGrid();
sumOfDiagonals = 0;
}
//Solve the problem
void Problem28::solve(){
//If the problem has already been solved do nothing and end the function
if(solved){
@@ -132,6 +136,15 @@ void Problem28::solve(){
solved = true;
}
//Reset the problem so it can be run again
void Problem28::reset(){
Problem::reset();
sumOfDiagonals = 0;
grid.clear();
setupGrid();
}
//Return a string with the solution to the problem
std::string Problem28::getString() const{
//If the problem hasn't been solved throw an exception
if(!solved){
@@ -161,10 +174,3 @@ uint64_t Problem28::getSum() const{
}
return sumOfDiagonals;
}
void Problem28::reset(){
Problem::reset();
sumOfDiagonals = 0;
grid.clear();
setupGrid();
}