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/Problem21.cpp
|
||||
//ProjectEuler/ProjectEulerCPP/Source/Problem21.cpp
|
||||
//Matthew Ellison
|
||||
// Created: 11-08-18
|
||||
//Modified: 07-14-19
|
||||
//Modified: 07-09-20
|
||||
//Evaluate the sum of all the amicable numbers under 10000
|
||||
//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
|
||||
@@ -31,17 +31,21 @@
|
||||
#include "../Headers/Problem21.hpp"
|
||||
|
||||
|
||||
//The top number that will be evaluated
|
||||
int Problem21::LIMIT = 10000; //The top number that will be evaluated
|
||||
|
||||
Problem21::Problem21() : Problem("Evaluate the sum of all the amicable numbers under 10000"){
|
||||
reserveVectors();
|
||||
}
|
||||
|
||||
//Reserve the size of the vector to speed up insertion
|
||||
void Problem21::reserveVectors(){
|
||||
divisorSum.reserve(LIMIT); //Reserving it now makes it faster later
|
||||
divisorSum.resize(LIMIT); //Make sure there are enough spaces
|
||||
}
|
||||
|
||||
//Constructor
|
||||
Problem21::Problem21() : Problem("Evaluate the sum of all the amicable numbers under 10000"){
|
||||
reserveVectors();
|
||||
}
|
||||
|
||||
//Solve the problem
|
||||
void Problem21::solve(){
|
||||
//If the problem has already been solved do nothing and end the function
|
||||
if(solved){
|
||||
@@ -87,6 +91,15 @@ void Problem21::solve(){
|
||||
solved = true;
|
||||
}
|
||||
|
||||
//Reset the problem so it can be run again
|
||||
void Problem21::reset(){
|
||||
Problem::reset();
|
||||
divisorSum.clear();
|
||||
amicable.clear();
|
||||
reserveVectors();
|
||||
}
|
||||
|
||||
//Return a string with the solution to the problem
|
||||
std::string Problem21::getString() const{
|
||||
//If the problem hasn't been solved throw an exception
|
||||
if(!solved){
|
||||
@@ -102,6 +115,7 @@ std::string Problem21::getString() const{
|
||||
return results.str();
|
||||
}
|
||||
|
||||
//Returns a vector with all of the amicable numbers calculated
|
||||
std::vector<uint64_t> Problem21::getAmicable() const{
|
||||
//If the problem hasn't been solved throw an exception
|
||||
if(!solved){
|
||||
@@ -110,6 +124,7 @@ std::vector<uint64_t> Problem21::getAmicable() const{
|
||||
return amicable;
|
||||
}
|
||||
|
||||
//Returns the sum of all of the amicable numbers
|
||||
uint64_t Problem21::getSum() const{
|
||||
//If the problem hasn't been solved throw an exception
|
||||
if(!solved){
|
||||
@@ -117,10 +132,3 @@ uint64_t Problem21::getSum() const{
|
||||
}
|
||||
return mee::getSum(amicable);
|
||||
}
|
||||
|
||||
void Problem21::reset(){
|
||||
Problem::reset();
|
||||
divisorSum.clear();
|
||||
amicable.clear();
|
||||
reserveVectors();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user