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,11 +1,11 @@
|
||||
//ProjectEuler/C++/Source/Problem15.hpp
|
||||
//ProjectEuler/ProjectEulerCPP/Source/Problem15.hpp
|
||||
//Matthew Ellison
|
||||
// Created: 09-29-18
|
||||
//Modified: 07-14-19
|
||||
//Modified: 07-09-20
|
||||
//How many routes from the top left corner to the bottom right corner are there through a 20×20 grid if you can only move right and down?
|
||||
//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
|
||||
@@ -30,9 +30,11 @@
|
||||
#include "../Headers/Problem15.hpp"
|
||||
|
||||
|
||||
int Problem15::WIDTH = 20;
|
||||
int Problem15::LENGTH = 20;
|
||||
int Problem15::WIDTH = 20; //The width of the grid
|
||||
int Problem15::LENGTH = 20; //The length of the grid
|
||||
|
||||
//This function acts as a handler for moving the position on the grid and counting the distance
|
||||
//It moves right first, then down
|
||||
void Problem15::move(int currentX, int currentY, uint64_t& numOfRoutes){
|
||||
//Check if you are at the end
|
||||
if((currentX == WIDTH) && (currentY == LENGTH)){
|
||||
@@ -51,9 +53,11 @@ void Problem15::move(int currentX, int currentY, uint64_t& numOfRoutes){
|
||||
}
|
||||
}
|
||||
|
||||
//Constructor
|
||||
Problem15::Problem15() : Problem("How many routes from the top left corner to the bottom right corner are there through a 20×20 grid if you can only move right and down?"), numOfRoutes(0){
|
||||
}
|
||||
|
||||
//Solve the problem
|
||||
void Problem15::solve(){
|
||||
//If the problem has already been solved do nothing and end the function
|
||||
if(solved){
|
||||
@@ -78,6 +82,13 @@ void Problem15::solve(){
|
||||
solved = true;
|
||||
}
|
||||
|
||||
//Reset the problem so it can be run again
|
||||
void Problem15::reset(){
|
||||
Problem::reset();
|
||||
numOfRoutes = 0;
|
||||
}
|
||||
|
||||
//Return a string with the solution to the problem
|
||||
std::string Problem15::getString() const{
|
||||
//If the problem hasn't been solved throw an exception
|
||||
if(!solved){
|
||||
@@ -89,6 +100,7 @@ std::string Problem15::getString() const{
|
||||
return results.str();
|
||||
}
|
||||
|
||||
//Returns the number of routes found
|
||||
uint64_t Problem15::getNumberOfRoutes() const{
|
||||
//If the problem hasn't been solved throw an exception
|
||||
if(!solved){
|
||||
@@ -96,8 +108,3 @@ uint64_t Problem15::getNumberOfRoutes() const{
|
||||
}
|
||||
return numOfRoutes;
|
||||
}
|
||||
|
||||
void Problem15::reset(){
|
||||
Problem::reset();
|
||||
numOfRoutes = 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user