Updated how results are retrieved

This commit is contained in:
2020-07-20 00:53:08 -04:00
parent 22871b71e9
commit 2616dabe6d
67 changed files with 132 additions and 434 deletions

View File

@@ -62,6 +62,9 @@ void Problem1::solve(){
//Stop the timer
timer.stop();
//Save the results
result << "The sum of all the numbers < " << MAX_NUMBER + 1 << " that are divisible by 3 or 5 is " << fullSum;
//Throw a flag to show the problem is solved
solved = true;
}
@@ -72,20 +75,8 @@ void Problem1::reset(){
fullSum = 0;
}
//Gets
//Return a string with the solution to the problem
std::string Problem1::getString() const{
//If the problem hasn't been solved throw an exception
if(!solved){
throw Unsolved();
}
//Create a string with the results and return it
std::stringstream results;
results << "The sum of all the numbers < " << MAX_NUMBER + 1 << " that are divisible by 3 or 5 is " << fullSum;
return results.str();
}
//Returns the requested sum
uint64_t Problem1::getSum() const{
//If the prblem hasn't been solved throw an exception
if(!solved){

View File

@@ -53,6 +53,9 @@ void Problem10::solve(){
//Stop the timer
timer.stop();
//Save the results
result << "The sum of all the primes less than " << GOAL_NUMBER + 1 << " is " << sum;
//Throw a flag to show the problem is solved
solved = true;
}
@@ -63,17 +66,6 @@ void Problem10::reset(){
sum = 0;
}
//Return a string with the solution to the problem
std::string Problem10::getString() const{
//If the problem hasn't been solved throw an exception
if(!solved){
throw Unsolved();
}
std::stringstream results;
results << "The sum of all the primes less than " << GOAL_NUMBER + 1 << " is " << sum;
return results.str();
}
//Returns the sum that was requested
uint64_t Problem10::getSum() const{
//If the problem hasn't been solved throw an exception

View File

@@ -174,6 +174,10 @@ void Problem11::solve(){
//Stop the timer
timer.stop();
//Save the results
result << "The greatest product of 4 number in a line is " << mee::getProduct(greatestProduct)
<< "\nThe numbers are " << greatestProduct.at(0) << ' ' << greatestProduct.at(1) << ' ' << greatestProduct.at(2) << ' ' << greatestProduct.at(3);
//Throw a flag to show the problem is solved
solved = true;
}
@@ -184,18 +188,6 @@ void Problem11::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){
throw Unsolved();
}
std::stringstream results;
results << "The greatest product of 4 number in a line is " << mee::getProduct(greatestProduct)
<< "\nThe numbers are " << greatestProduct.at(0) << ' ' << greatestProduct.at(1) << ' ' << greatestProduct.at(2) << ' ' << greatestProduct.at(3);
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

View File

@@ -66,6 +66,9 @@ void Problem12::solve(){
//Stop the timer
timer.stop();
//Save the results
result << "The triangular number " << sum << " is a sum of all numbers >= " << counter - 1 << " and has " << divisors.size() << " divisors";
//Throw a flag to show the problem is solved
solved = true;
}
@@ -78,17 +81,6 @@ void Problem12::reset(){
counter = 2;
}
//Return a string with the solution to the problem
std::string Problem12::getString() const{
//If the problem hasn't been solved throw an exception
if(!solved){
throw Unsolved();
}
std::stringstream results;
results << "The triangular number " << sum << " is a sum of all numbers >= " << counter - 1 << " and has " << divisors.size() << " divisors";
return results.str();
}
//Returns the triangular number
int64_t Problem12::getTriangularNumber() const{
//If the problem hasn't been solved throw an exception

View File

@@ -275,6 +275,10 @@ void Problem13::solve(){
//Stop the timer
timer.stop();
//Save the results
result << "The sum of all " << nums.size() << " numbers is " << sum
<< "\nThe first 10 digits of the sum of the numbers is " << sum.get_str().substr(0, 10);
//Throw a flag to show the problem is solved
solved = true;
}
@@ -287,19 +291,6 @@ void Problem13::reset(){
reserveVectors();
}
//Return a string with the solution to the problem
std::string Problem13::getString() const{
//If the problem hasn't been solved throw an exception
if(!solved){
throw Unsolved();
}
std::stringstream results;
results << "The sum of all " << nums.size() << " numbers is " << sum
<< "\nThe first 10 digits of the sum of the numbers is " << sum.get_str().substr(0, 10);
return results.str();
}
//Returns the list 50-digit numbers
std::vector<mpz_class> Problem13::getNumbers() const{
//If the problem hasn't been solved throw an exception

View File

@@ -82,6 +82,9 @@ void Problem14::solve(){
//Stop the timer
timer.stop();
//Save the results
result << "The number " << maxNum << " produced a chain of " << maxLength << " steps";
//Throw a flag to show the problem is solved
solved = true;
}
@@ -93,18 +96,6 @@ void Problem14::reset(){
maxNum = 0;
}
//Return a string with the solution to the problem
std::string Problem14::getString() const{
//If the problem hasn't been solved throw an exception
if(!solved){
throw Unsolved();
}
std::stringstream results;
results << "The number " << maxNum << " produced a chain of " << maxLength << " steps";
return results.str();
}
//Returns the length of the requested chain
uint64_t Problem14::getLength() const{
//If the problem hasn't been solved throw an exception

View File

@@ -78,6 +78,9 @@ void Problem15::solve(){
//Stop the timer
timer.stop();
//Save the results
result << "The number of routes is " << numOfRoutes;
//Throw a flag to show the problem is solved
solved = true;
}
@@ -88,18 +91,6 @@ void Problem15::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){
throw Unsolved();
}
std::stringstream results;
results << "The number of routes is " << numOfRoutes;
return results.str();
}
//Returns the number of routes found
uint64_t Problem15::getNumberOfRoutes() const{
//If the problem hasn't been solved throw an exception

View File

@@ -65,6 +65,10 @@ void Problem16::solve(){
//Stop the timer
timer.stop();
//Save the results
result << NUM_TO_POWER << '^' << POWER << " = " << num
<< "\nThe sum of the elements is " << sumOfElements;
//Throw a flag to show the problem is solved
solved = true;
}
@@ -76,20 +80,6 @@ void Problem16::reset(){
sumOfElements = 0;
}
//Return a string with the solution to the problem
std::string Problem16::getString() const{
//If the problem hasn't been solved throw an exception
if(!solved){
throw Unsolved();
}
std::stringstream results;
results << NUM_TO_POWER << '^' << POWER << " = " << num
<< "\nThe sum of the elements is " << sumOfElements;
return results.str();
}
//Returns the number that was calculated
mpz_class Problem16::getNumber() const{
//If the problem hasn't been solved throw an exception

View File

@@ -195,6 +195,9 @@ void Problem17::solve(){
//Stop the timer
timer.stop();
//Save the results
result << "The number of letters is " << letterCount;
//Throw a flag to show the problem is solved
solved = true;
}
@@ -205,17 +208,6 @@ void Problem17::reset(){
letterCount = 0;
}
//Return a string with the solution to the problem
std::string Problem17::getString() const{
//If the problem hasn't been solved throw an exception
if(!solved){
throw Unsolved();
}
std::stringstream results;
results << "The number of letters is " << letterCount;
return results.str();
}
//Returns the number of letters asked for
uint64_t Problem17::getLetterCount() const{
//If the problem hasn't been solved throw an exception

View File

@@ -135,6 +135,9 @@ void Problem18::solve(){
//Stop the timer
timer.stop();
//Save the results
result << "The value of the longest path is " << actualTotal;
//Throw a flag to show the problem is solved
solved = true;
}
@@ -147,18 +150,6 @@ void Problem18::reset(){
actualTotal = 0;
}
//Return a string with the solution to the problem
std::string Problem18::getString() const{
//If the problem hasn't been solved throw an exception
if(!solved){
throw Unsolved();
}
std::stringstream results;
results << "The value of the longest path is " << actualTotal;
return results.str();
}
//Returns the pyramid that was traversed as a string
std::string Problem18::getPyramid(){
//If the problem hasn't been solved throw an exception

View File

@@ -171,6 +171,9 @@ void Problem19::solve(){
//Stop the timer
timer.stop();
//Save the results
result << "There are " << totalSundays << " Sundays that landed on the first of the months from " << START_YEAR << " to " << END_YEAR;
//Throw a flag to show the problem is solved
solved = true;
}
@@ -181,17 +184,6 @@ void Problem19::reset(){
totalSundays = 0;
}
//Return a string with the solution to the problem
std::string Problem19::getString() const{
//If the problem hasn't been solved throw an exception
if(!solved){
throw Unsolved();
}
std::stringstream results;
results << "There are " << totalSundays << " Sundays that landed on the first of the months from " << START_YEAR << " to " << END_YEAR;
return results.str();
}
//Returns the total sundays that were asked for
uint64_t Problem19::getTotalSundays() const{
//If the problem hasn't been solved throw an exception

View File

@@ -61,6 +61,9 @@ void Problem2::solve(){
//Stop the timer
timer.stop();
//Save the results
result << "The sum of the even Fibonacci numbers less than 4,000,000 is " << fullSum;
//Throw a flag to show the problem is solved
solved = true;
}
@@ -71,17 +74,6 @@ void Problem2::reset(){
fullSum = 0;
}
//Return a string with the solution to the problem
std::string Problem2::getString() const{
//If the problem hasn't been solved throw an exception
if(!solved){
throw Unsolved();
}
std::stringstream results;
results << "The sum of the even Fibonacci numbers less than 4,000,000 is " << fullSum;
return results.str();
}
//Returns the requested sum
uint64_t Problem2::getSum() const{
//If the problem hasn't been solved throw an exception

View File

@@ -64,6 +64,10 @@ void Problem20::solve(){
//Stop the timer
timer.stop();
//Save the results
result << "100! = " << num.get_str()
<< "\nThe sum of the digits is: " << sum;
//Throw a flag to show the problem is solved
solved = true;
}
@@ -75,19 +79,6 @@ void Problem20::reset(){
num = 1;
}
//Return a string with the solution to the problem
std::string Problem20::getString() const{
//If the problem hasn't been solved throw an exception
if(!solved){
throw Unsolved();
}
std::stringstream results;
//Print the results
results << "100! = " << num.get_str()
<< "\nThe sum of the digits is: " << sum;
return results.str();
}
//Returns the number 100!
mpz_class Problem20::getNumber() const{
//If the problem hasn't been solved throw an exception

View File

@@ -87,6 +87,13 @@ void Problem21::solve(){
//Stop the timer
timer.stop();
//Save the results
result << "All amicable numbers less than 10000 are\n";
for(unsigned int cnt = 0;cnt < amicable.size();++cnt){
result << amicable.at(cnt) << '\n';
}
result << "The sum of all of these amicable numbers is " << mee::getSum(amicable);
//Throw a flag to show the problem is solved
solved = true;
}
@@ -99,22 +106,6 @@ void Problem21::reset(){
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){
throw Unsolved();
}
std::stringstream results;
results << "All amicable numbers less than 10000 are\n";
for(unsigned int cnt = 0;cnt < amicable.size();++cnt){
results << amicable.at(cnt) << '\n';
}
results << "The sum of all of these amicable numbers is " << mee::getSum(amicable);
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

View File

@@ -445,6 +445,9 @@ void Problem22::solve(){
//Stop the timer
timer.stop();
//Save the results
result << "The answer to the question is " << mee::getSum(prod);
//Throw a flag to show the problem is solved
solved = true;
}
@@ -457,17 +460,6 @@ void Problem22::reset(){
reserveVectors();
}
//Return a string with the solution to the problem
std::string Problem22::getString() const{
//If the problem hasn't been solved throw an exception
if(!solved){
throw Unsolved();
}
std::stringstream results;
results << "The answer to the question is " << mee::getSum(prod);
return results.str();
}
//Returns the vector of the names being scored
std::vector<std::string> Problem22::getNames() const{
//If the problem hasn't been solved throw an exception

View File

@@ -104,6 +104,9 @@ void Problem23::solve(){
//Stop the timer
timer.stop();
//Save the results
result << "The answer is " << sum;
//Throw a flag to show the problem is solved
solved = true;
}
@@ -116,17 +119,6 @@ void Problem23::reset(){
reserveVectors();
}
//Return a string with the solution to the problem
std::string Problem23::getString() const{
//If the problem hasn't been solved throw an exception
if(!solved){
throw Unsolved();
}
std::stringstream results;
results << "The answer is " << sum;
return results.str();
}
//Returns the sum of the numbers asked for
uint64_t Problem23::getSum() const{
//If the problem hasn't been solved throw an exception

View File

@@ -55,6 +55,9 @@ void Problem24::solve(){
//Stop the timer
timer.stop();
//Save the results
result << "The 1 millionth permutation is " << permutations.at(NEEDED_PERM - 1);
//Throw a flag to show the problem is solved
solved = true;
}
@@ -65,18 +68,6 @@ void Problem24::reset(){
permutations.clear();
}
//Return a string with the solution to the problem
std::string Problem24::getString() const{
//If the problem hasn't been solved throw an exception
if(!solved){
throw Unsolved();
}
std::stringstream results;
//Print the results
results << "The 1 millionth permutation is " << permutations.at(NEEDED_PERM - 1);
return results.str();
}
//Returns a vector with all of the permutations
std::vector<std::string> Problem24::getPermutationsList() const{
//If the problem hasn't been solved throw an exception

View File

@@ -61,6 +61,10 @@ void Problem25::solve(){
//Stop the timer
timer.stop();
//Save the results
result << "The first Fibonacci number with " << NUM_DIGITS << " digits is " << number
<< "\nIts index is " << index;
//Throw a flag to show the problem is solved
solved = true;
}
@@ -72,19 +76,6 @@ void Problem25::reset(){
index = 2;
}
//Return a string with the solution to the problem
std::string Problem25::getString() const{
//If the problem hasn't been solved throw an exception
if(!solved){
throw Unsolved();
}
std::stringstream results;
results << "The first Fibonacci number with " << NUM_DIGITS << " digits is " << number
<< "\nIts index is " << index;
return results.str();
}
//Returns the Fibonacci number asked for
mpz_class Problem25::getNumber() const{
//If the problem hasn't been solved throw an exception

View File

@@ -89,6 +89,10 @@ void Problem26::solve(){
//Stop the timer
timer.stop();
//Save the results
result << "The longest cycle is " << longestCycle << " digits long\n"
<< "It is started with the number " << longestNumber;
//Throw a flag to show the problem is solved
solved = true;
}
@@ -100,20 +104,6 @@ void Problem26::reset(){
longestNumber = 1;
}
//Return a string with the solution to the problem
std::string Problem26::getString() const{
//If the problem hasn't been solved throw an exception
if(!solved){
throw Unsolved();
}
std::stringstream results;
results << "The longest cycle is " << longestCycle << " digits long\n"
<< "It is started with the number " << longestNumber;
return results.str();
}
//Returns the length of the longest cycle
unsigned int Problem26::getLongestCycle() const{
//If the problem hasn't been solved throw an exception

View File

@@ -70,6 +70,11 @@ void Problem27::solve(){
//Stop the timer
timer.stop();
//Save the results
result << "The greatest number of primes found is " << topN
<< "\nIt was found with A = " << topA << ", B = " << topB
<< "\nThe product of A and B is " << topA * topB;
//Throw a flag to show the problem is solved
solved = true;
}
@@ -81,21 +86,6 @@ void Problem27::reset(){
primes.clear();
}
//Return a string with the solution to the problem
std::string Problem27::getString() const{
//If the problem hasn't been solved throw an exception
if(!solved){
throw Unsolved();
}
std::stringstream results;
results << "The greatest number of primes found is " << topN
<< "\nIt was found with A = " << topA << ", B = " << topB
<< "\nThe product of A and B is " << topA * topB;
return results.str();
}
//Returns the top A that was generated
int64_t Problem27::getTopA() const{
//If the problem hasn't been solved throw an exception

View File

@@ -132,6 +132,9 @@ void Problem28::solve(){
//Stop the timer
timer.stop();
//Save the results
result << "The sum of the diagonals in the given grid is " << sumOfDiagonals;
//Throw a flag to show the problem is solved
solved = true;
}
@@ -144,19 +147,6 @@ void Problem28::reset(){
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){
throw Unsolved();
}
std::stringstream results;
results << "The sum of the diagonals in the given grid is " << sumOfDiagonals;
return results.str();
}
//Returns the grid
std::vector<std::vector<int>> Problem28::getGrid() const{
//If the problem hasn't been solved throw an exception

View File

@@ -73,6 +73,9 @@ void Problem29::solve(){
//Stop the timer
timer.stop();
//Save the results
result << "The number of unique values generated by a^b for " << BOTTOM_A << " <= a <= " << TOP_A << " and " << BOTTOM_B << " <= b <= " << TOP_B << " is " << unique.size();
//Throw a flag to show the problem is solved
solved = true;
}
@@ -83,19 +86,6 @@ void Problem29::reset(){
unique.clear();
}
//Return a string with the solution to the problem
std::string Problem29::getString() const{
//If the problem hasn't been solved throw an exception
if(!solved){
throw Unsolved();
}
std::stringstream results;
results << "The number of unique values generated by a^b for " << BOTTOM_A << " <= a <= " << TOP_A << " and " << BOTTOM_B << " <= b <= " << TOP_B << " is " << unique.size();
return results.str();
}
//Returns the lowest possible value for a
unsigned int Problem29::getBottomA() const{
//If the problem hasn't been solved throw an exception

View File

@@ -54,6 +54,9 @@ void Problem3::solve(){
//Stop the timer
timer.stop();
//Save the results
result << "The largest factor of the number " << GOAL_NUMBER << " is " << factors[factors.size() - 1];
//Throw a flag to show the problem is solved
solved = true;
}
@@ -64,17 +67,6 @@ void Problem3::reset(){
factors.clear();
}
//Return a string with the solution to the problem
std::string Problem3::getString() const{
//If the problem hasn't been solved throw an exception
if(!solved){
throw Unsolved();
}
std::stringstream results;
results << "The largest factor of the number " << GOAL_NUMBER << " is " << factors[factors.size() - 1];
return results.str();
}
//Returns the list of factors of the number
std::vector<uint64_t> Problem3::getFactors() const{
//If the problem hasn't been solved throw an exception

View File

@@ -85,6 +85,9 @@ void Problem30::solve(){
//Throw a flag to show the problem is solved
solved = true;
//Save the results
result << "The sum of all the numbers that can be written as the sum of the fifth powers of their digits is " << getSumOfList();
}
//Reset the problem so it can be run again
@@ -93,19 +96,6 @@ void Problem30::reset(){
sumOfFifthNumbers.clear();
}
//Return a string with the solution to the problem
std::string Problem30::getString() const{
//If the problem hasn't been solved throw an exception
if(!solved){
throw Unsolved();
}
std::stringstream results;
results << "The sum of all the numbers that can be written as the sum of the fifth powers of their digits is " << getSumOfList();
return results.str();
}
//This returns the top number to be checked
uint64_t Problem30::getTopNum() const{
//If the problem hasn't been solved throw an exception

View File

@@ -67,6 +67,9 @@ void Problem31::solve(){
//Stop the timer
timer.stop();
//Save the results
result << "There are " << permutations << " ways to make 2 pounds with the given denominations of coins";
//Throw a flag to show the problem is solved
solved = true;
}
@@ -77,19 +80,6 @@ void Problem31::reset(){
permutations = 0;
}
//Return a string with the solution to the problem
std::string Problem31::getString() const{
//If the problem hasn't been solved throw an exception
if(!solved){
throw Unsolved();
}
std::stringstream results;
results << "There are " << permutations << " ways to make 2 pounds with the given denominations of coins";
return results.str();
}
//Returns the number of correct permutations of the coins
int Problem31::getPermutations() const{
//If the problem hasn't been solved throw an exception

View File

@@ -75,6 +75,9 @@ void Problem4::solve(){
//Stop the timer
timer.stop();
//Save the results
result << "The largest palindrome is " << *(palindromes.end() - 1);
//Throw a flag to show the problem is solved
solved = true;
}
@@ -85,18 +88,6 @@ void Problem4::reset(){
palindromes.clear();
}
//Return a string with the solution to the problem
std::string Problem4::getString() const{
//If the problem hasn't been solved throw an exception
if(!solved){
throw Unsolved();
}
//Print the results
std::stringstream results;
results << "The largest palindrome is " << *(palindromes.end() - 1);
return results.str();
}
//Returns the list of all palindromes
std::vector<uint64_t> Problem4::getPalindromes() const{
//If the problem hasn't been solved throw an exception

View File

@@ -72,6 +72,9 @@ void Problem5::solve(){
//Stop the timer
timer.stop();
//Save the results
result << "The smallest positive number evenly divisible by all numbers 1-20 is " << smallestNum;
//Throw a flag to show the problem is solved
solved = true;
}
@@ -82,17 +85,6 @@ void Problem5::reset(){
smallestNum = 0;
}
//Return a string with the solution to the problem
std::string Problem5::getString() const{
//If the problem hasn't been solved throw an exception
if(!solved){
throw Unsolved();
}
std::stringstream results;
results << "The smallest positive number evenly divisible by all numbers 1-20 is " << smallestNum;
return results.str();
}
//Returns the requested number
int Problem5::getNumber() const{
//If the problem hasn't been solved throw an exception

View File

@@ -58,6 +58,9 @@ void Problem6::solve(){
//Stop the timer
timer.stop();
//Save the results
result << "The difference between the sum of the squares and the square of the sum of all numbers from 1-100 is " << abs(sumOfSquares - squareOfSum);
//Throw a flag to show the problem is solved
solved = true;
}
@@ -68,17 +71,6 @@ void Problem6::reset(){
sumOfSquares = squareOfSum = 0;
}
//Return a string with the solution to the problem
std::string Problem6::getString() const{
//If the problem hasn't been solved throw an exception
if(!solved){
throw Unsolved();
}
std::stringstream results;
results << "The difference between the sum of the squares and the square of the sum of all numbers from 1-100 is " << abs(sumOfSquares - squareOfSum);
return results.str();
}
//Returns the sum of all the squares
uint64_t Problem6::getSumOfSquares() const{
//If the problem hasn't been solved throw an exception

View File

@@ -311,6 +311,9 @@ void Problem67::solve(){
//Stop the timer
timer.stop();
//Save the results
result << "The value of the longest path is " << actualTotal;
//Throw a flag to show the problem is solved
solved = true;
}
@@ -323,18 +326,6 @@ void Problem67::reset(){
actualTotal = 0;
}
//Return a string with the solution to the problem
std::string Problem67::getString() const{
//If the problem hasn't been solved throw an exception
if(!solved){
throw Unsolved();
}
std::stringstream results;
results << "The value of the longest path is " << actualTotal;
return results.str();
}
//Returns the pyramid that was traversed as a string
std::string Problem67::getPyramid() const{
//If the problem hasn't been solved throw an exception

View File

@@ -54,6 +54,9 @@ void Problem7::solve(){
//Stop the timer
timer.stop();
//Save the results
result << "The " << NUMBER_OF_PRIMES << "th prime number is " << primes.at(primes.size() - 1);
//Throw a flag to show the problem is solved
solved = true;
}
@@ -63,17 +66,6 @@ void Problem7::reset(){
Problem::reset();
}
//Return a string with the solution to the problem
std::string Problem7::getString() const{
//If the problem hasn't been solved throw an exception
if(!solved){
throw Unsolved();
}
std::stringstream results;
results << "The " << NUMBER_OF_PRIMES << "th prime number is " << primes.at(primes.size() - 1);
return results.str();
}
//Returns the requested prime number
uint64_t Problem7::getPrime() const{
//If the problem hasn't been solved throw an exception

View File

@@ -84,6 +84,10 @@ void Problem8::solve(){
//Stop the timer
timer.stop();
//Save the results
result << "The greatest product is " << maxProduct
<< "\nThe numbers are " << maxNums;
//Throw a flag to show the problem is solved
solved = true;
}
@@ -95,18 +99,6 @@ void Problem8::reset(){
maxProduct = 0;
}
//Return a string with the solution to the problem
std::string Problem8::getString() const{
//If the problem hasn't been solved throw an exception
if(!solved){
throw Unsolved();
}
std::stringstream results;
results << "The greatest product is " << maxProduct
<< "\nThe numbers are " << maxNums;
return results.str();
}
//Returns the string of numbers that produces the largest product
std::string Problem8::getLargestNums() const{
//If the problem hasn't been solved throw an exception

View File

@@ -66,6 +66,15 @@ void Problem9::solve(){
//Stop the timer
timer.stop();
//Save the results
if(found){
result << "The Pythagorean triplet is " << a << ' ' << b << ' ' << (int)c
<< "\nThe numbers' product is " << a * b * (int)c;
}
else{
result << "The number was not found!";
}
//Throw a flag to show the problem is solved
solved = true;
}
@@ -79,24 +88,6 @@ void Problem9::reset(){
found = false;
}
//Return a string with the solution to the problem
std::string Problem9::getString() const{
//If the problem hasn't been solved throw an exception
if(!solved){
throw Unsolved();
}
std::stringstream results;
if(found){
results << "The Pythagorean triplet is " << a << ' ' << b << ' ' << (int)c
<< "\nThe numbers' product is " << a * b * (int)c;
}
else{
results << "The number was not found!";
}
return results.str();
}
//Returns the length of the first side
int Problem9::getSideA() const{
//If the problem hasn't been solved throw an exception