mirror of
https://bitbucket.org/Mattrixwv/projecteulercpp.git
synced 2025-12-06 17:13:59 -05:00
Added a benchmark tool
This commit is contained in:
@@ -30,6 +30,10 @@
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
void Problem28::setupGrid(){
|
||||
//Set the size of the grid to 1001 x 1001
|
||||
for(int cnt = 0;cnt < 1001;++cnt){
|
||||
grid.emplace_back();
|
||||
@@ -37,11 +41,10 @@ Problem28::Problem28() : Problem("What is the sum of the number on the diagonals
|
||||
grid.at(cnt).push_back(0);
|
||||
}
|
||||
}
|
||||
sumOfDiagonals = 0;
|
||||
}
|
||||
|
||||
//Sets up the grid
|
||||
void Problem28::setupGrid(){
|
||||
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
|
||||
int currentNum = 1;
|
||||
@@ -117,7 +120,7 @@ void Problem28::solve(){
|
||||
|
||||
|
||||
//Setup the grid
|
||||
setupGrid();
|
||||
createGrid();
|
||||
//Find the sum of the diagonals in the grid
|
||||
findSum();
|
||||
|
||||
@@ -158,3 +161,10 @@ uint64_t Problem28::getSum() const{
|
||||
}
|
||||
return sumOfDiagonals;
|
||||
}
|
||||
|
||||
void Problem28::reset(){
|
||||
Problem::reset();
|
||||
sumOfDiagonals = 0;
|
||||
grid.clear();
|
||||
setupGrid();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user