Updated to work with the new libraries

This commit is contained in:
2021-07-03 02:38:00 -04:00
parent fd54eb90d8
commit 9660fe9287
82 changed files with 794 additions and 1008 deletions

View File

@@ -1,7 +1,7 @@
//ProjectEuler/ProjectEulerCPP/Source/Problem14.cpp
//ProjectEuler/ProjectEulerCPP/src/Problems/Problem14.cpp
//Matthew Ellison
// Created: 09-29-18
//Modified: 08-28-20
//Modified: 07-02-21
/*
The following iterative sequence is defined for the set of positive integers:
n → n/2 (n is even)
@@ -10,7 +10,7 @@ Which starting number, under one million, produces the longest chain?
*/
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/myClasses
/*
Copyright (C) 2020 Matthew Ellison
Copyright (C) 2021 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
@@ -28,8 +28,8 @@ Which starting number, under one million, produces the longest chain?
#include <cinttypes>
#include <string>
#include <sstream>
#include <string>
#include "Problems/Problem14.hpp"
@@ -67,6 +67,7 @@ void Problem14::solve(){
//Start the timer
timer.start();
//Loop through all numbers less than 1000000 and check them agains the series
for(uint64_t currentNum = 1;currentNum <= MAX_NUM;++currentNum){
uint64_t currentLength = checkSeries(currentNum);
@@ -77,6 +78,7 @@ void Problem14::solve(){
}
}
//Stop the timer
timer.stop();
@@ -92,27 +94,19 @@ void Problem14::reset(){
//Gets
//Return a string with the solution to the problem
std::string Problem14::getResult(){
if(!solved){
throw Unsolved();
}
std::string Problem14::getResult() const{
solvedCheck("result");
std::stringstream result;
result << "The number " << maxNum << " produced a chain of " << maxLength << " steps";
return result.str();
}
//Returns the length of the requested chain
uint64_t Problem14::getLength() const{
//If the problem hasn't been solved throw an exception
if(!solved){
throw Unsolved();
}
solvedCheck("length of the longest chain");
return maxLength;
}
//Returns the starting number of the requested chain
uint64_t Problem14::getStartingNumber() const{
//If the problem hasn't been solved throw an exception
if(!solved){
throw Unsolved();
}
solvedCheck("starting number of the longest chain");
return maxNum;
}