mirror of
https://bitbucket.org/Mattrixwv/projecteulercpp.git
synced 2025-12-07 01:23:57 -05:00
Updated various typoes and removed some unneeded code
This commit is contained in:
@@ -37,14 +37,11 @@ protected:
|
|||||||
public:
|
public:
|
||||||
//Constructors
|
//Constructors
|
||||||
Problem() : solved(false){
|
Problem() : solved(false){
|
||||||
|
|
||||||
}
|
}
|
||||||
Problem(std::string description) : description(description), solved(false){
|
Problem(std::string description) : description(description), solved(false){
|
||||||
|
|
||||||
}
|
}
|
||||||
//Destructor
|
//Destructor
|
||||||
virtual ~Problem(){
|
virtual ~Problem(){
|
||||||
|
|
||||||
}
|
}
|
||||||
//Gets
|
//Gets
|
||||||
virtual std::string getDescription() const{
|
virtual std::string getDescription() const{
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ private:
|
|||||||
static uint64_t MAX_NUMBER; //The highest number to be tested
|
static uint64_t MAX_NUMBER; //The highest number to be tested
|
||||||
//Instance variables
|
//Instance variables
|
||||||
uint64_t fullSum; //For the sum of all the numbers
|
uint64_t fullSum; //For the sum of all the numbers
|
||||||
std::vector<uint64_t> numbers; //Holds all the numbers
|
|
||||||
public:
|
public:
|
||||||
//Constructor
|
//Constructor
|
||||||
Problem1();
|
Problem1();
|
||||||
|
|||||||
@@ -34,9 +34,9 @@ class Problem10 : public Problem{
|
|||||||
private:
|
private:
|
||||||
//Variables
|
//Variables
|
||||||
//Static variables
|
//Static variables
|
||||||
static uint64_t GOAL_NUMBER;
|
static uint64_t GOAL_NUMBER; //The largest number to check for primes
|
||||||
//Instance variables
|
//Instance variables
|
||||||
uint64_t sum;
|
uint64_t sum; //The sum of all of the prime
|
||||||
public:
|
public:
|
||||||
//Constructor
|
//Constructor
|
||||||
Problem10();
|
Problem10();
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ private:
|
|||||||
//Functions
|
//Functions
|
||||||
//This function acts as a handler for moving the position on the grid and counting the distance
|
//This function acts as a handler for moving the position on the grid and counting the distance
|
||||||
//It moves right first, then down
|
//It moves right first, then down
|
||||||
void move(int currentX, int currentY, uint64_t& numOfRoutes);
|
void move(int currentX, int currentY);
|
||||||
public:
|
public:
|
||||||
//Constructor
|
//Constructor
|
||||||
Problem15();
|
Problem15();
|
||||||
|
|||||||
@@ -34,7 +34,8 @@ class Problem17 : public Problem{
|
|||||||
private:
|
private:
|
||||||
//Variables
|
//Variables
|
||||||
//Static variables
|
//Static variables
|
||||||
static int TOP_NUM; //This is the largest number to get the words of
|
static int START_NUM; //This is the smallest number to get the words of
|
||||||
|
static int STOP_NUM; //This is the largest number to get the words of
|
||||||
//Instance variables
|
//Instance variables
|
||||||
uint64_t letterCount; //This is the cumulative number of letters in the words of the numbers
|
uint64_t letterCount; //This is the cumulative number of letters in the words of the numbers
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ private:
|
|||||||
public:
|
public:
|
||||||
//Constructor
|
//Constructor
|
||||||
Problem6();
|
Problem6();
|
||||||
//Operational functinos
|
//Operational functions
|
||||||
virtual void solve(); //Solve the problem
|
virtual void solve(); //Solve the problem
|
||||||
virtual void reset(); //Reset the problem so it can be run again
|
virtual void reset(); //Reset the problem so it can be run again
|
||||||
//Gets
|
//Gets
|
||||||
|
|||||||
@@ -34,9 +34,9 @@ class Problem9 : public Problem{
|
|||||||
private:
|
private:
|
||||||
//Variables
|
//Variables
|
||||||
//Instance variables
|
//Instance variables
|
||||||
int a; //Holds the position on the first side
|
int a; //Holds the size of the first side
|
||||||
int b; //Holds the position on the second side
|
int b; //Holds the size of the second side
|
||||||
double c; //Holds the hyp
|
double c; //Holds the size of the hyp
|
||||||
bool found; //A flag to determine if we have found the solution yet
|
bool found; //A flag to determine if we have found the solution yet
|
||||||
public:
|
public:
|
||||||
//Constructor
|
//Constructor
|
||||||
|
|||||||
@@ -52,18 +52,13 @@ void Problem1::solve(){
|
|||||||
for(uint64_t cnt = 1;cnt <= MAX_NUMBER;++cnt){
|
for(uint64_t cnt = 1;cnt <= MAX_NUMBER;++cnt){
|
||||||
//If either 3 or 5 divides it evenly then add it to the vector
|
//If either 3 or 5 divides it evenly then add it to the vector
|
||||||
if((cnt % 3) == 0){
|
if((cnt % 3) == 0){
|
||||||
numbers.push_back(cnt);
|
fullSum += cnt;
|
||||||
}
|
}
|
||||||
else if((cnt % 5) == 0){
|
else if((cnt % 5) == 0){
|
||||||
numbers.push_back(cnt);
|
fullSum += cnt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Get the sum of all numbers
|
|
||||||
for(uint64_t num : numbers){
|
|
||||||
fullSum += num;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.stop();
|
timer.stop();
|
||||||
|
|
||||||
@@ -75,7 +70,6 @@ void Problem1::solve(){
|
|||||||
void Problem1::reset(){
|
void Problem1::reset(){
|
||||||
Problem::reset();
|
Problem::reset();
|
||||||
fullSum = 0;
|
fullSum = 0;
|
||||||
numbers.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
#include "../Headers/Problem10.hpp"
|
#include "../Headers/Problem10.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
//The largest number to check for primes
|
||||||
uint64_t Problem10::GOAL_NUMBER = 2000000 - 1; //2,000,000 - 1 because is needs to be < instead of <=
|
uint64_t Problem10::GOAL_NUMBER = 2000000 - 1; //2,000,000 - 1 because is needs to be < instead of <=
|
||||||
|
|
||||||
//Constructor
|
//Constructor
|
||||||
@@ -56,7 +57,7 @@ void Problem10::solve(){
|
|||||||
solved = true;
|
solved = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Reset the rpoblem so it can be run agian
|
//Reset the problem so it can be run again
|
||||||
void Problem10::reset(){
|
void Problem10::reset(){
|
||||||
Problem::reset();
|
Problem::reset();
|
||||||
sum = 0;
|
sum = 0;
|
||||||
|
|||||||
@@ -253,6 +253,7 @@ void Problem13::reserveVectors(){
|
|||||||
//Constructor
|
//Constructor
|
||||||
Problem13::Problem13() : Problem("Work out the first ten digits of the sum of the one-hundred 50-digit numbers"), sum(0){
|
Problem13::Problem13() : Problem("Work out the first ten digits of the sum of the one-hundred 50-digit numbers"), sum(0){
|
||||||
reserveVectors();
|
reserveVectors();
|
||||||
|
sum = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Solve the problem
|
//Solve the problem
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ Which starting number, under one million, produces the longest chain?
|
|||||||
|
|
||||||
|
|
||||||
//This is the top number that you will be checking against the series
|
//This is the top number that you will be checking against the series
|
||||||
uint64_t Problem14::MAX_NUM = 999999;
|
uint64_t Problem14::MAX_NUM = 1000000 - 1;
|
||||||
|
|
||||||
//This function follows the rules of the sequence and returns its length
|
//This function follows the rules of the sequence and returns its length
|
||||||
uint64_t Problem14::checkSeries(uint64_t num){
|
uint64_t Problem14::checkSeries(uint64_t num){
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ 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
|
//This function acts as a handler for moving the position on the grid and counting the distance
|
||||||
//It moves right first, then down
|
//It moves right first, then down
|
||||||
void Problem15::move(int currentX, int currentY, uint64_t& numOfRoutes){
|
void Problem15::move(int currentX, int currentY){
|
||||||
//Check if you are at the end
|
//Check if you are at the end
|
||||||
if((currentX == WIDTH) && (currentY == LENGTH)){
|
if((currentX == WIDTH) && (currentY == LENGTH)){
|
||||||
++numOfRoutes;
|
++numOfRoutes;
|
||||||
@@ -44,12 +44,12 @@ void Problem15::move(int currentX, int currentY, uint64_t& numOfRoutes){
|
|||||||
|
|
||||||
//Move right if possible
|
//Move right if possible
|
||||||
if(currentX < WIDTH){
|
if(currentX < WIDTH){
|
||||||
move(currentX + 1, currentY, numOfRoutes);
|
move(currentX + 1, currentY);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Move down if possible
|
//Move down if possible
|
||||||
if(currentY < LENGTH){
|
if(currentY < LENGTH){
|
||||||
move(currentX, currentY + 1, numOfRoutes);
|
move(currentX, currentY + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,7 +73,7 @@ void Problem15::solve(){
|
|||||||
|
|
||||||
//We write this as a recursive function
|
//We write this as a recursive function
|
||||||
//When in a location it always moves right first, then down
|
//When in a location it always moves right first, then down
|
||||||
move(currentX, currentY, numOfRoutes);
|
move(currentX, currentY);
|
||||||
|
|
||||||
//Stop the timer
|
//Stop the timer
|
||||||
timer.stop();
|
timer.stop();
|
||||||
|
|||||||
@@ -31,7 +31,8 @@
|
|||||||
|
|
||||||
|
|
||||||
//This is the largest number to get the words of
|
//This is the largest number to get the words of
|
||||||
int Problem17::TOP_NUM = 1000;
|
int Problem17::START_NUM = 1;
|
||||||
|
int Problem17::STOP_NUM = 1000;
|
||||||
|
|
||||||
//This function makes a word out of the number passed into it
|
//This function makes a word out of the number passed into it
|
||||||
std::string Problem17::makeWord(int num){
|
std::string Problem17::makeWord(int num){
|
||||||
@@ -186,7 +187,7 @@ void Problem17::solve(){
|
|||||||
timer.start();
|
timer.start();
|
||||||
|
|
||||||
//Step through every element in nums and get the word representations of the numbers
|
//Step through every element in nums and get the word representations of the numbers
|
||||||
for(int cnt = 1;cnt <= TOP_NUM;++cnt){
|
for(int cnt = START_NUM;cnt <= STOP_NUM;++cnt){
|
||||||
std::string words = makeWord(cnt); //Get the words of each number in turn
|
std::string words = makeWord(cnt); //Get the words of each number in turn
|
||||||
letterCount += countLetters(words); //Add the number of letters to the running tally
|
letterCount += countLetters(words); //Add the number of letters to the running tally
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
|
|
||||||
|
|
||||||
//Holds the largest number that we are looking for
|
//Holds the largest number that we are looking for
|
||||||
uint64_t Problem2::TOP_NUM = 4000000;
|
uint64_t Problem2::TOP_NUM = 4000000 - 1;
|
||||||
|
|
||||||
//Constructor
|
//Constructor
|
||||||
Problem2::Problem2() : Problem("What is the sum of the even Fibonacci numbers less than 4,000,000?"), fullSum(0){
|
Problem2::Problem2() : Problem("What is the sum of the even Fibonacci numbers less than 4,000,000?"), fullSum(0){
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//ProjectEuler/ProjectEulerCPP/Source/Problem31.cpp
|
//ProjectEuler/ProjectEulerCPP/Source/Problem31.cpp
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 06-19-20
|
// Created: 06-19-20
|
||||||
//Modified: 07-09-20
|
//Modified: 07-11-20
|
||||||
//How many different ways can £2 be made using any number of coins?
|
//How many different ways can £2 be made using any number of coins?
|
||||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/myClasses
|
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/myClasses
|
||||||
/*
|
/*
|
||||||
@@ -92,5 +92,9 @@ std::string Problem31::getString() const{
|
|||||||
|
|
||||||
//Returns the number of correct permutations of the coins
|
//Returns the number of correct permutations of the coins
|
||||||
int Problem31::getPermutations() const{
|
int Problem31::getPermutations() const{
|
||||||
|
//If the problem hasn't been solved throw an exception
|
||||||
|
if(!solved){
|
||||||
|
throw unsolved();
|
||||||
|
}
|
||||||
return permutations;
|
return permutations;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -247,7 +247,7 @@ void Problem67::invert(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Constructor
|
//Constructor
|
||||||
Problem67::Problem67() : Problem("Find the maximum total from the top to the bottom of the pyramid."){
|
Problem67::Problem67() : Problem("Find the maximum total from the top to the bottom of the pyramid."), actualTotal(0){
|
||||||
}
|
}
|
||||||
|
|
||||||
//Solve the problem
|
//Solve the problem
|
||||||
|
|||||||
Reference in New Issue
Block a user