mirror of
https://bitbucket.org/Mattrixwv/projecteulercpp.git
synced 2025-12-06 17:13:59 -05:00
Updated various typoes and removed some unneeded code
This commit is contained in:
@@ -37,14 +37,11 @@ protected:
|
||||
public:
|
||||
//Constructors
|
||||
Problem() : solved(false){
|
||||
|
||||
}
|
||||
Problem(std::string description) : description(description), solved(false){
|
||||
|
||||
}
|
||||
//Destructor
|
||||
virtual ~Problem(){
|
||||
|
||||
}
|
||||
//Gets
|
||||
virtual std::string getDescription() const{
|
||||
|
||||
@@ -38,7 +38,6 @@ private:
|
||||
static uint64_t MAX_NUMBER; //The highest number to be tested
|
||||
//Instance variables
|
||||
uint64_t fullSum; //For the sum of all the numbers
|
||||
std::vector<uint64_t> numbers; //Holds all the numbers
|
||||
public:
|
||||
//Constructor
|
||||
Problem1();
|
||||
|
||||
@@ -34,9 +34,9 @@ class Problem10 : public Problem{
|
||||
private:
|
||||
//Variables
|
||||
//Static variables
|
||||
static uint64_t GOAL_NUMBER;
|
||||
static uint64_t GOAL_NUMBER; //The largest number to check for primes
|
||||
//Instance variables
|
||||
uint64_t sum;
|
||||
uint64_t sum; //The sum of all of the prime
|
||||
public:
|
||||
//Constructor
|
||||
Problem10();
|
||||
|
||||
@@ -36,8 +36,8 @@ private:
|
||||
//Static variables
|
||||
static uint64_t GOAL_DIVISORS; //The number of divisors that you want
|
||||
//Instance variables
|
||||
int64_t sum; //The sum of the numbers up to counter
|
||||
int64_t counter; //The next number to be added to sum
|
||||
int64_t sum; //The sum of the numbers up to counter
|
||||
int64_t counter; //The next number to be added to sum
|
||||
std::vector<int64_t> divisors; //Holds the divisors of the triangular number sum
|
||||
public:
|
||||
//Constructor
|
||||
|
||||
@@ -42,7 +42,7 @@ private:
|
||||
//Functions
|
||||
//This function acts as a handler for moving the position on the grid and counting the distance
|
||||
//It moves right first, then down
|
||||
void move(int currentX, int currentY, uint64_t& numOfRoutes);
|
||||
void move(int currentX, int currentY);
|
||||
public:
|
||||
//Constructor
|
||||
Problem15();
|
||||
|
||||
@@ -34,7 +34,8 @@ class Problem17 : public Problem{
|
||||
private:
|
||||
//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
|
||||
uint64_t letterCount; //This is the cumulative number of letters in the words of the numbers
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ private:
|
||||
public:
|
||||
//Constructor
|
||||
Problem6();
|
||||
//Operational functinos
|
||||
//Operational functions
|
||||
virtual void solve(); //Solve the problem
|
||||
virtual void reset(); //Reset the problem so it can be run again
|
||||
//Gets
|
||||
|
||||
@@ -34,9 +34,9 @@ class Problem9 : public Problem{
|
||||
private:
|
||||
//Variables
|
||||
//Instance variables
|
||||
int a; //Holds the position on the first side
|
||||
int b; //Holds the position on the second side
|
||||
double c; //Holds the hyp
|
||||
int a; //Holds the size of the first side
|
||||
int b; //Holds the size of the second side
|
||||
double c; //Holds the size of the hyp
|
||||
bool found; //A flag to determine if we have found the solution yet
|
||||
public:
|
||||
//Constructor
|
||||
|
||||
@@ -52,18 +52,13 @@ void Problem1::solve(){
|
||||
for(uint64_t cnt = 1;cnt <= MAX_NUMBER;++cnt){
|
||||
//If either 3 or 5 divides it evenly then add it to the vector
|
||||
if((cnt % 3) == 0){
|
||||
numbers.push_back(cnt);
|
||||
fullSum += cnt;
|
||||
}
|
||||
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
|
||||
timer.stop();
|
||||
|
||||
@@ -75,7 +70,6 @@ void Problem1::solve(){
|
||||
void Problem1::reset(){
|
||||
Problem::reset();
|
||||
fullSum = 0;
|
||||
numbers.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#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 <=
|
||||
|
||||
//Constructor
|
||||
@@ -56,7 +57,7 @@ void Problem10::solve(){
|
||||
solved = true;
|
||||
}
|
||||
|
||||
//Reset the rpoblem so it can be run agian
|
||||
//Reset the problem so it can be run again
|
||||
void Problem10::reset(){
|
||||
Problem::reset();
|
||||
sum = 0;
|
||||
|
||||
@@ -253,6 +253,7 @@ void Problem13::reserveVectors(){
|
||||
//Constructor
|
||||
Problem13::Problem13() : Problem("Work out the first ten digits of the sum of the one-hundred 50-digit numbers"), sum(0){
|
||||
reserveVectors();
|
||||
sum = 0;
|
||||
}
|
||||
|
||||
//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
|
||||
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
|
||||
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
|
||||
//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
|
||||
if((currentX == WIDTH) && (currentY == LENGTH)){
|
||||
++numOfRoutes;
|
||||
@@ -44,12 +44,12 @@ void Problem15::move(int currentX, int currentY, uint64_t& numOfRoutes){
|
||||
|
||||
//Move right if possible
|
||||
if(currentX < WIDTH){
|
||||
move(currentX + 1, currentY, numOfRoutes);
|
||||
move(currentX + 1, currentY);
|
||||
}
|
||||
|
||||
//Move down if possible
|
||||
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
|
||||
//When in a location it always moves right first, then down
|
||||
move(currentX, currentY, numOfRoutes);
|
||||
move(currentX, currentY);
|
||||
|
||||
//Stop the timer
|
||||
timer.stop();
|
||||
|
||||
@@ -31,7 +31,8 @@
|
||||
|
||||
|
||||
//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
|
||||
std::string Problem17::makeWord(int num){
|
||||
@@ -186,7 +187,7 @@ void Problem17::solve(){
|
||||
timer.start();
|
||||
|
||||
//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
|
||||
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
|
||||
uint64_t Problem2::TOP_NUM = 4000000;
|
||||
uint64_t Problem2::TOP_NUM = 4000000 - 1;
|
||||
|
||||
//Constructor
|
||||
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
|
||||
//Matthew Ellison
|
||||
// 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?
|
||||
//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
|
||||
int Problem31::getPermutations() const{
|
||||
//If the problem hasn't been solved throw an exception
|
||||
if(!solved){
|
||||
throw unsolved();
|
||||
}
|
||||
return permutations;
|
||||
}
|
||||
|
||||
@@ -247,7 +247,7 @@ void Problem67::invert(){
|
||||
}
|
||||
|
||||
//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
|
||||
|
||||
Reference in New Issue
Block a user