mirror of
https://bitbucket.org/Mattrixwv/projecteulercpp.git
synced 2025-12-07 01:23:57 -05:00
Updated to work with the new libraries
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
//ProjectEuler/ProjectEulerCPP/headers/Problems/Problem1.hpp
|
||||
//Matthew Ellison
|
||||
// Created: 09-28-18
|
||||
//Modified: 10-26-20
|
||||
//Modified: 07-02-21
|
||||
//What is the sum of all the multiples of 3 or 5 that are less than 1000
|
||||
//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
|
||||
@@ -20,12 +20,10 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PROBLEM1_HPP
|
||||
#define PROBLEM1_HPP
|
||||
|
||||
|
||||
#include <vector>
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include "Problem.hpp"
|
||||
@@ -46,13 +44,15 @@ public:
|
||||
virtual void solve(); //Solve the problem
|
||||
virtual void reset(); //Reset the problem so it can be run again
|
||||
//Gets
|
||||
virtual std::string getResult(); //Return a string with the solution to the problem
|
||||
virtual std::string getResult() const; //Return a string with the solution to the problem
|
||||
uint64_t getSum() const; //Returns the requested sum
|
||||
};
|
||||
|
||||
|
||||
/* Results:
|
||||
The sum of all the numbers < 1000 that are divisible by 3 or 5 is 233168
|
||||
It took an average of 50.000 nanoseconds to run this problem over 100 iterations
|
||||
*/
|
||||
|
||||
#endif //PROBLEM1_HPP
|
||||
|
||||
#endif //PROBLEM1_HPP
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
//ProjectEuler/ProjectEulerCPP/headers/Problems/Problem10.hpp
|
||||
//Matthew Ellison
|
||||
// Created: 09-28-18
|
||||
//Modified: 08-28-20
|
||||
//Modified: 07-02-21
|
||||
//Find the sum of all the primes below two million
|
||||
//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
|
||||
@@ -20,7 +20,6 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PROBLEM10_HPP
|
||||
#define PROBLEM10_HPP
|
||||
|
||||
@@ -44,13 +43,15 @@ public:
|
||||
virtual void solve(); //Solve the problem
|
||||
virtual void reset(); //Reset the problem so it can be run again
|
||||
//Gets
|
||||
virtual std::string getResult(); //Return a string with the solution to the problem
|
||||
virtual std::string getResult() const; //Return a string with the solution to the problem
|
||||
uint64_t getSum() const; //Returns the sum that was requested
|
||||
};
|
||||
|
||||
|
||||
/* Results:
|
||||
The sum of all the primes less than 2000000 is 142913828922
|
||||
It took an average of 171.141 milliseconds to run this problem over 100 iterations
|
||||
*/
|
||||
|
||||
#endif //PROBLEM10_HPP
|
||||
|
||||
#endif //PROBLEM10_HPP
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//ProjectEuler/ProjectEulerCPP/headers/Problems/Problem11.hpp
|
||||
//Matthew Ellison
|
||||
// Created: 09-29-18
|
||||
//Modified: 08-28-20
|
||||
//Modified: 07-02-21
|
||||
//What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the 20×20 grid?
|
||||
/*
|
||||
08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08
|
||||
@@ -27,7 +27,7 @@
|
||||
*/
|
||||
//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
|
||||
@@ -42,7 +42,6 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PROBLEM11_HPP
|
||||
#define PROBLEM11_HPP
|
||||
|
||||
@@ -66,15 +65,17 @@ public:
|
||||
virtual void solve(); //Solve the problem
|
||||
virtual void reset(); //Reset the problem so it can be run again
|
||||
//Gets
|
||||
virtual std::string getResult(); //Return a string with the solution to the problem
|
||||
virtual std::string getResult() const; //Return a string with the solution to the problem
|
||||
std::vector<int> getNumbers() const; //Returns the numbers that were being searched
|
||||
int getProduct() const; //Returns the product that was requested
|
||||
};
|
||||
|
||||
|
||||
/* Results:
|
||||
The greatest product of 4 number in a line is 70600674
|
||||
The numbers are 89 94 97 87
|
||||
It took an average of 11.201 microseconds to run this problem over 100 iterations
|
||||
*/
|
||||
|
||||
#endif //PROBLEM11_HPP
|
||||
|
||||
#endif //PROBLEM11_HPP
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
//ProjectEuler/ProjectEulerCPP/headers/Problems/Problem12.hpp
|
||||
//Matthew Ellison
|
||||
// Created: 09-27-18
|
||||
//Modified: 08-28-20
|
||||
//Modified: 07-02-21
|
||||
//What is the value of the first triangle number to have over five hundred divisors?
|
||||
//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
|
||||
@@ -19,14 +20,13 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PROBLEM12_HPP
|
||||
#define PROBLEM12_HPP
|
||||
|
||||
|
||||
#include <vector>
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "Problem.hpp"
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
virtual void solve(); //Solve the problem
|
||||
virtual void reset(); //Reset the problem so it can be run again
|
||||
//Gets
|
||||
virtual std::string getResult(); //Return a string with the solution to the problem
|
||||
virtual std::string getResult() const; //Return a string with the solution to the problem
|
||||
int64_t getTriangularNumber() const; //Returns the triangular number
|
||||
int64_t getLastNumberAdded() const; //Get the final number that was added to the triangular number
|
||||
std::vector<int64_t> getDivisorsOfTriangularNumber() const; //Returns the list of divisors of the requested number
|
||||
@@ -59,4 +59,5 @@ The triangular number 76576500 is a sum of all numbers >= 12375 and has 576 divi
|
||||
It took an average of 280.536 milliseconds to run this problem over 100 iterations
|
||||
*/
|
||||
|
||||
#endif //PROBLEM12_HPP
|
||||
|
||||
#endif //PROBLEM12_HPP
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//ProjectEuler/ProjectEulerCPP/headers/Problems/Problem13.hpp
|
||||
//Matthew Ellison
|
||||
// Created: 09-29-18
|
||||
//Modified: 08-28-20
|
||||
//Modified: 07-02-21
|
||||
//Work out the first ten digits of the sum of the following one-hundred 50-digit numbers
|
||||
/*
|
||||
37107287533902102798797998220837590246510135740250
|
||||
@@ -110,7 +110,7 @@
|
||||
//You can find more information about them at https://gmplib.org/
|
||||
//When compiling this file you need to have the gmp library installed as well as linking the libraries to your executable using the -lgmpxx and -lgmp flags
|
||||
/*
|
||||
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
|
||||
@@ -125,15 +125,13 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PROBLEM13_HPP
|
||||
#define PROBLEM13_HPP
|
||||
|
||||
|
||||
#include <cinttypes>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "gmpxx.h" //This is part of the gmp library
|
||||
#include <gmpxx.h>
|
||||
#include "Problem.hpp"
|
||||
|
||||
|
||||
@@ -154,7 +152,7 @@ public:
|
||||
virtual void solve(); //Solve the problem
|
||||
virtual void reset(); //Reset the problem so it can be run again
|
||||
//Gets
|
||||
virtual std::string getResult(); //Return a string with the solution to the problem
|
||||
virtual std::string getResult() const; //Return a string with the solution to the problem
|
||||
std::vector<mpz_class> getNumbers() const; //Returns the list 50-digit numbers
|
||||
mpz_class getSum() const; //Returns the sum of the 50-digit numbers
|
||||
};
|
||||
@@ -166,4 +164,5 @@ The first 10 digits of the sum of the numbers is 5537376230
|
||||
It took an average of 13.270 microseconds to run this problem over 100 iterations
|
||||
*/
|
||||
|
||||
#endif //PROBLEM13_HPP
|
||||
|
||||
#endif //PROBLEM13_HPP
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//ProjectEuler/ProjectEulerCPP/headers/Problems/Problem14.hpp
|
||||
//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
|
||||
@@ -25,7 +25,6 @@ Which starting number, under one million, produces the longest chain?
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PROBLEM14_HPP
|
||||
#define PROBLEM14_HPP
|
||||
|
||||
@@ -53,14 +52,16 @@ public:
|
||||
virtual void solve(); //Solve the problem
|
||||
virtual void reset(); //Reset the problem so it can be run again
|
||||
//Gets
|
||||
virtual std::string getResult(); //Return a string with the solution to the problem
|
||||
uint64_t getLength() const; //Returns the length of the requested chain
|
||||
virtual std::string getResult() const; //Return a string with the solution to the problem
|
||||
uint64_t getLength() const; //Returns the length of the requested chain
|
||||
uint64_t getStartingNumber() const; //Returns the starting number of the requested chain
|
||||
};
|
||||
|
||||
|
||||
/* Results:
|
||||
The number 837799 produced a chain of 525 steps
|
||||
It took an average of 197.008 milliseconds to run this problem over 100 iterations
|
||||
*/
|
||||
|
||||
#endif //PROBLEM14_HPP
|
||||
|
||||
#endif //PROBLEM14_HPP
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
//ProjectEuler/ProjectEulerCPP/headers/Problems/Problem15.hpp
|
||||
//Matthew Ellison
|
||||
// Created: 09-29-18
|
||||
//Modified: 08-28-20
|
||||
//Modified: 07-02-21
|
||||
//How many routes from the top left corner to the bottom right corner are there through a 20×20 grid if you can only move right and down?
|
||||
//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
|
||||
@@ -50,12 +50,15 @@ public:
|
||||
virtual void solve(); //Solve the problem
|
||||
virtual void reset(); //Reset the problem so it can be run again
|
||||
//Gets
|
||||
virtual std::string getResult(); //Return a string with the solution to the problem
|
||||
virtual std::string getResult() const; //Return a string with the solution to the problem
|
||||
uint64_t getNumberOfRoutes() const; //Returns the number of routes found
|
||||
};
|
||||
|
||||
|
||||
/* Results:
|
||||
The number of routes is 137846528820
|
||||
It took an average of 18.010 minutes to run this problem through 10 iterations
|
||||
*/
|
||||
|
||||
#endif //PROBLEM15_HPP
|
||||
|
||||
#endif //PROBLEM15_HPP
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
//ProjectEuler/ProjectEulerCPP/headers/Problems/Problem16.hpp
|
||||
//Matthew Ellison
|
||||
// Created: 09-28-18
|
||||
//Modified: 08-28-20
|
||||
//Modified: 07-02-21
|
||||
//What is the sum of the digits of the number 2^1000?
|
||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/myClasses
|
||||
//This file contains a header from the gmp library. The library is used for large integers.
|
||||
//You can find more information about them at https://gmplib.org/
|
||||
//When compiling this file you need to have the gmp library installed as well as linking the libraries to your executable using the -lgmpxx and -lgmp flags
|
||||
/*
|
||||
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
|
||||
@@ -23,7 +23,6 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PROBLEM16_HPP
|
||||
#define PROBLEM16_HPP
|
||||
|
||||
@@ -49,15 +48,17 @@ public:
|
||||
virtual void solve(); //Solve the problem
|
||||
virtual void reset(); //Reset the problem so it can be run again
|
||||
//Gets
|
||||
virtual std::string getResult(); //Return a string with the solution to the problem
|
||||
virtual std::string getResult() const; //Return a string with the solution to the problem
|
||||
mpz_class getNumber() const; //Returns the number that was calculated
|
||||
int getSum() const; //Return the sum of the digits of the number
|
||||
};
|
||||
|
||||
|
||||
/* Results:
|
||||
2^1000 = 10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376
|
||||
The sum of the elements is 1366
|
||||
It took an average of 4.806 microseconds to run this problem over 100 iterations
|
||||
*/
|
||||
|
||||
#endif //PROBLEM16_HPP
|
||||
|
||||
#endif //PROBLEM16_HPP
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
//ProjectEuler/ProjectEulerCPP/headers/Problems/Problem17.hpp
|
||||
//Matthew Ellison
|
||||
// Created: 10-05-18
|
||||
//Modified: 08-28-20
|
||||
//Modified: 07-02-21
|
||||
//If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used?
|
||||
//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
|
||||
@@ -50,12 +50,15 @@ public:
|
||||
virtual void solve(); //Solve the problem
|
||||
virtual void reset(); //Reset the problem so it can be run again
|
||||
//Gets
|
||||
virtual std::string getResult(); //Return a string with the solution to the problem
|
||||
virtual std::string getResult() const; //Return a string with the solution to the problem
|
||||
uint64_t getLetterCount() const; //Returns the number of letters asked for
|
||||
};
|
||||
|
||||
|
||||
/* Results:
|
||||
The number of letters is 21124
|
||||
It took an average of 220.126 microseconds to run this problem over 100 iterations
|
||||
*/
|
||||
|
||||
#endif //Problem17_HPP
|
||||
|
||||
#endif //Problem17_HPP
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//ProjectEuler/ProjectEulerCPP/headers/Problems/Problem18.hpp
|
||||
//Matthew Ellison
|
||||
// Created: 11-01-18
|
||||
//Modified: 08-28-20
|
||||
//Modified: 07-02-21
|
||||
//Find the maximum total from top to bottom
|
||||
/*
|
||||
75
|
||||
@@ -23,7 +23,7 @@
|
||||
//This is done using a breadth first search
|
||||
//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
|
||||
@@ -38,14 +38,13 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PROBLEM18_HPP
|
||||
#define PROBLEM18_HPP
|
||||
|
||||
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "Problem.hpp"
|
||||
|
||||
|
||||
@@ -69,7 +68,7 @@ private:
|
||||
|
||||
//Functions
|
||||
void invert(); //This list turns every number in the vector into 100 - num
|
||||
void setupList();
|
||||
void setupList(); //Setup the list of numbers
|
||||
protected:
|
||||
//Variables
|
||||
//Static variables
|
||||
@@ -81,10 +80,10 @@ public:
|
||||
virtual void solve(); //Solve the problem
|
||||
virtual void reset(); //Reset the problem so it can be run again
|
||||
//Gets
|
||||
virtual std::string getResult(); //Return a string with the solution to the problem
|
||||
std::string getPyramid(); //Returns the pyramid that was traversed as a string
|
||||
std::string getTrail(); //Returns the trail the algorithm took as a string
|
||||
int getTotal() const; //Returns the total that was asked for
|
||||
virtual std::string getResult() const; //Return a string with the solution to the problem
|
||||
std::string getPyramid() const; //Returns the pyramid that was traversed as a string
|
||||
std::string getTrail() const; //Returns the trail the algorithm took as a string
|
||||
int getTotal() const; //Returns the total that was asked for
|
||||
};
|
||||
|
||||
/* Results:
|
||||
@@ -92,4 +91,4 @@ The value of the longest path is 1074
|
||||
It took an average of 9.925 microseconds to run this problem over 100 iterations
|
||||
*/
|
||||
|
||||
#endif //PROBLEM18_HPP
|
||||
#endif //PROBLEM18_HPP
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//ProjectEuler/ProjectEulerCPP/headers/Problems/Problem19.hpp
|
||||
//Matthew Ellison
|
||||
// Created: 09-28-18
|
||||
//Modified: 08-28-20
|
||||
//Modified: 07-02-21
|
||||
//How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?
|
||||
/*
|
||||
You are given the following information, but you may prefer to do some research for yourself.
|
||||
@@ -16,7 +16,7 @@ A leap year occurs on any year evenly divisible by 4, but not on a century unles
|
||||
*/
|
||||
//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
|
||||
@@ -31,7 +31,6 @@ A leap year occurs on any year evenly divisible by 4, but not on a century unles
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PROBLEM19_HPP
|
||||
#define PROBLEM19_HPP
|
||||
|
||||
@@ -62,12 +61,15 @@ public:
|
||||
virtual void solve(); //Solve the problem
|
||||
virtual void reset(); //Reset the problem so it can be run again
|
||||
//Gets
|
||||
virtual std::string getResult(); //Return a string with the solution to the problem
|
||||
uint64_t getTotalSundays() const; //Returns the total sundays that were asked for
|
||||
virtual std::string getResult() const; //Return a string with the solution to the problem
|
||||
uint64_t getTotalSundays() const; //Returns the total sundays that were asked for
|
||||
};
|
||||
|
||||
|
||||
/* Results
|
||||
There are 171 Sundays that landed on the first of the months from 1901 to 2000
|
||||
It took an average of 1.400 milliseconds to run this problem over 100 iterations
|
||||
*/
|
||||
|
||||
#endif //PROBLEM19_HPP
|
||||
|
||||
#endif //PROBLEM19_HPP
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
//ProjectEuler/ProjectEulerCPP/headers/Problems/Problem2.hpp
|
||||
//Matthew Ellison
|
||||
// Created: 09-28-18
|
||||
//Modified: 08-28-20
|
||||
//Modified: 07-02-21
|
||||
//The sum of the even Fibonacci numbers less than 4,000,000
|
||||
//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
|
||||
@@ -20,11 +20,10 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef PROBLEM2_HPP
|
||||
#define PROBLEM2_HPP
|
||||
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include "Problem.hpp"
|
||||
@@ -44,13 +43,15 @@ public:
|
||||
virtual void solve(); //Solve the problem
|
||||
virtual void reset(); //Reset the problem so it can be run again
|
||||
//Gets
|
||||
virtual std::string getResult(); //Return a string with the solution to the problem
|
||||
virtual std::string getResult() const; //Return a string with the solution to the problem
|
||||
uint64_t getSum() const; //Returns the requested sum
|
||||
};
|
||||
|
||||
|
||||
/* Results:
|
||||
The sum of the even Fibonacci numbers less than 4,000,000 is 4613732
|
||||
It took an average of 324.000 nanoseconds to run this problem over 100 iterations
|
||||
*/
|
||||
|
||||
#endif //PROBLEM2_HPP
|
||||
|
||||
#endif //PROBLEM2_HPP
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
//ProjectEuler/ProjectEulerCPP/headers/Problems/Problem20.hpp
|
||||
//Matthew Ellison
|
||||
// Created: 11-07-18
|
||||
//Modified: 08-28-20
|
||||
//Modified: 07-02-21
|
||||
//What is the sum of the digits of 100!?
|
||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/myClasses
|
||||
//This file contains a header from the gmp library. The library is used for large integers.
|
||||
//You can find more information about them at https://gmplib.org/
|
||||
//When compiling this file you need to have the gmp library installed as well as linking the libraries to your executable using the -lgmpxx and -lgmp flags
|
||||
/*
|
||||
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
|
||||
@@ -23,7 +23,6 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PROBLEM20_HPP
|
||||
#define PROBLEM20_HPP
|
||||
|
||||
@@ -47,16 +46,18 @@ public:
|
||||
virtual void solve(); //Solve the problem
|
||||
virtual void reset(); //Reset the problem so it can be run again
|
||||
//Gets
|
||||
virtual std::string getResult(); //Return a string with the solution to the problem
|
||||
virtual std::string getResult() const; //Return a string with the solution to the problem
|
||||
mpz_class getNumber() const; //Returns the number 100!
|
||||
std::string getNumberString() const; //Returns the number 100! in a string
|
||||
uint64_t getSum() const; //Returns the sum of the digits of 100!
|
||||
};
|
||||
|
||||
|
||||
/* Results:
|
||||
100! = 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000
|
||||
The sum of the digits is: 648
|
||||
It took an average of 4.094 microseconds to run this problem over 100 iterations
|
||||
*/
|
||||
|
||||
#endif //PROBLEM20_HPP
|
||||
|
||||
#endif //PROBLEM20_HPP
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
//ProjectEuler/ProjectEulerCPP/headers/Problems/Problem21.hpp
|
||||
//Matthew Ellison
|
||||
// Created: 11-08-18
|
||||
//Modified: 08-28-20
|
||||
//Modified: 07-02-21
|
||||
//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) 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
|
||||
@@ -20,14 +20,13 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PROBLEM21_HPP
|
||||
#define PROBLEM21_HPP
|
||||
|
||||
|
||||
#include <cinttypes>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "Problem.hpp"
|
||||
|
||||
|
||||
@@ -49,7 +48,7 @@ public:
|
||||
virtual void solve(); //Solve the problem
|
||||
virtual void reset(); //Reset the problem so it can be run again
|
||||
//Gets
|
||||
virtual std::string getResult(); //Return a string with the solution to the problem
|
||||
virtual std::string getResult() const; //Return a string with the solution to the problem
|
||||
std::vector<uint64_t> getAmicable() const; //Returns a vector with all of the amicable numbers calculated
|
||||
uint64_t getSum() const; //Returns the sum of all of the amicable numbers
|
||||
};
|
||||
@@ -71,4 +70,5 @@ The sum of all of these amicable numbers is 31626
|
||||
It took an average of 4.310 milliseconds to run this problem over 100 iterations
|
||||
*/
|
||||
|
||||
#endif //PROBLEM21_HPP
|
||||
|
||||
#endif //PROBLEM21_HPP
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
//ProjectEuler/ProjectEulerCPP/headers/Problems/Problem22.hpp
|
||||
//Matthew Ellison
|
||||
// Created: 11-09-18
|
||||
//Modified: 08-28-20
|
||||
//Modified: 07-02-21
|
||||
//What is the total of all the name scores in the file?
|
||||
//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
|
||||
@@ -20,7 +20,6 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PROBLEM22_HPP
|
||||
#define PROBLEM22_HPP
|
||||
|
||||
@@ -50,14 +49,16 @@ public:
|
||||
virtual void solve(); //Solve the problem
|
||||
virtual void reset(); //Reset the problem so it can be run again
|
||||
//Gets
|
||||
virtual std::string getResult(); //Return a string with the solution to the problem
|
||||
virtual std::string getResult() const; //Return a string with the solution to the problem
|
||||
std::vector<std::string> getNames() const; //Returns the vector of the names being scored
|
||||
uint64_t getNameScoreSum() const; //Returns the sum of the names scores
|
||||
};
|
||||
|
||||
|
||||
/* Results:
|
||||
The answer to the question is 871198282
|
||||
It took an average of 436.559 microseconds to run this problem over 100 iterations
|
||||
*/
|
||||
|
||||
#endif //Problem22
|
||||
|
||||
#endif //Problem22
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
//ProjectEuler/ProjectEulerCPP/headers/Problems/Problem23.hpp
|
||||
//Matthew Ellison
|
||||
// Created: 11-09-18
|
||||
//Modified: 08-28-20
|
||||
//Modified: 07-02-21
|
||||
//Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers
|
||||
//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
|
||||
@@ -20,14 +20,13 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PROBLEM23_HPP
|
||||
#define PROBLEM23_HPP
|
||||
|
||||
|
||||
#include <vector>
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "Problem.hpp"
|
||||
|
||||
|
||||
@@ -50,13 +49,15 @@ public:
|
||||
virtual void solve(); //Solve the problem
|
||||
virtual void reset(); //Reset the problem so it can be run again
|
||||
//Gets
|
||||
virtual std::string getResult(); //Return a string with the solution to the problem
|
||||
virtual std::string getResult() const; //Return a string with the solution to the problem
|
||||
uint64_t getSum() const; //Returns the sum of the numbers asked for
|
||||
};
|
||||
|
||||
|
||||
/* Results:
|
||||
The answer is 4179871
|
||||
It took an average of 5.902 seconds to run this problem over 100 iterations
|
||||
*/
|
||||
|
||||
#endif //PROBLEM23_HPP
|
||||
|
||||
#endif //PROBLEM23_HPP
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
//ProjectEuler/ProjectEulerCPP/headers/Problems/Problem24.hpp
|
||||
//Matthew Ellison
|
||||
// Created: 11-11-18
|
||||
//Modified: 08-28-20
|
||||
//Modified: 07-02-21
|
||||
//What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?
|
||||
//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
|
||||
@@ -20,7 +20,6 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PROBLEM24_HPP
|
||||
#define PROBLEM24_HPP
|
||||
|
||||
@@ -44,14 +43,16 @@ public:
|
||||
virtual void solve(); //Solve the problem
|
||||
virtual void reset(); //Reset the problem so it can be run again
|
||||
//Gets
|
||||
virtual std::string getResult(); //Return a string with the solution to the problem
|
||||
virtual std::string getResult() const; //Return a string with the solution to the problem
|
||||
std::vector<std::string> getPermutationsList() const; //Returns a vector with all of the permutations
|
||||
std::string getPermutation() const; //Returns the specific permutations you are looking for
|
||||
};
|
||||
|
||||
|
||||
/* Results
|
||||
The 1 millionth permutation is 2783915460
|
||||
It took an average of 1.157 seconds to run this problem over 100 iterations
|
||||
*/
|
||||
|
||||
#endif //PROBLEM24_HPP
|
||||
|
||||
#endif //PROBLEM24_HPP
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
//ProjectEuler/ProjectEulerCPP/headers/Problems/Problem25.hpp
|
||||
//Matthew Ellison
|
||||
// Created: 11-13-18
|
||||
//Modified: 08-28-20
|
||||
//Modified: 07-02-21
|
||||
//What is the index of the first term in the Fibonacci sequence to contain 1000 digits?
|
||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/myClasses
|
||||
//This file contains a header from the gmp library. The library is used for large integers.
|
||||
//You can find more information about them at https://gmplib.org/
|
||||
//When compiling this file you need to have the gmp library installed as well as linking the libraries to your executable using the -lgmpxx and -lgmp flags
|
||||
/*
|
||||
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
|
||||
@@ -23,13 +23,12 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PROBLEM25_HPP
|
||||
#define PROBLEM25_HPP
|
||||
|
||||
|
||||
#include <string>
|
||||
#include "gmpxx.h"
|
||||
#include <gmpxx.h>
|
||||
#include "Problem.hpp"
|
||||
|
||||
|
||||
@@ -48,7 +47,7 @@ public:
|
||||
virtual void solve(); //Solve the problem
|
||||
virtual void reset(); //Reset the problem so it can be run again
|
||||
//Gets
|
||||
virtual std::string getResult(); //Return a string with the solution to the problem
|
||||
virtual std::string getResult() const; //Return a string with the solution to the problem
|
||||
mpz_class getNumber() const; //Returns the Fibonacci number asked for
|
||||
std::string getNumberString() const; //Returns the Fibonacci number asked for as a string
|
||||
mpz_class getIndex() const; //Returns the index of the requested Fibonacci number
|
||||
@@ -62,4 +61,4 @@ Its index is 4782
|
||||
It took an average of 241.017 milliseconds to run this problem over 100 iterations
|
||||
*/
|
||||
|
||||
#endif //PROBLEM25_HPP
|
||||
#endif //PROBLEM25_HPP
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
//ProjectEuler/ProjectEulerCPP/headers/Problems/Problem26.hpp
|
||||
//Matthew Ellison
|
||||
// Created: 07-28-19
|
||||
//Modified: 08-28-20
|
||||
//Modified: 07-02-21
|
||||
//Find the value of d < 1000 for which 1/d contains the longest recurring cycle in its decimal fraction part.
|
||||
//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
|
||||
@@ -20,8 +20,6 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef PROBLEM26_HPP
|
||||
#define PROBLEM26_HPP
|
||||
|
||||
@@ -45,7 +43,7 @@ public:
|
||||
virtual void solve(); //Solve the problem
|
||||
virtual void reset(); //Reset the problem so it can be run again
|
||||
//Gets
|
||||
virtual std::string getResult(); //Return a string with the solution to the problem
|
||||
virtual std::string getResult() const; //Return a string with the solution to the problem
|
||||
unsigned int getLongestCycle() const; //Returns the length of the longest cycle
|
||||
unsigned int getLongestNumber() const; //Returns the denominator that starts the longest cycle
|
||||
};
|
||||
@@ -57,4 +55,5 @@ It is started with the number 983
|
||||
It took an average of 9.989 milliseconds to run this problem over 100 iterations
|
||||
*/
|
||||
|
||||
#endif //PROBLEM26_HPP
|
||||
|
||||
#endif //PROBLEM26_HPP
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
//ProjectEuler/ProjectEulerCPP/headers/Problems/Problem27.hpp
|
||||
//Matthew Ellison
|
||||
// Created: 09-14-19
|
||||
//Modified: 08-28-20
|
||||
//Modified: 07-02-21
|
||||
//Find the product of the coefficients, |a| < 1000 and |b| <= 1000, for the quadratic expression that produces the maximum number of primes for consecutive values of n, starting with n=0.
|
||||
//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
|
||||
@@ -20,13 +20,12 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PROBLEM27_HPP
|
||||
#define PROBLEM27_HPP
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "Problem.hpp"
|
||||
|
||||
@@ -46,12 +45,13 @@ public:
|
||||
virtual void solve(); //Solve the problem
|
||||
virtual void reset(); //Reset the problem so it can be run again
|
||||
//Gets
|
||||
virtual std::string getResult(); //Return a string with the solution to the problem
|
||||
virtual std::string getResult() const; //Return a string with the solution to the problem
|
||||
int64_t getTopA() const; //Returns the top A that was generated
|
||||
int64_t getTopB() const; //Returns the top B that was generated
|
||||
int64_t getTopN() const; //Returns the top N that was generated
|
||||
};
|
||||
|
||||
|
||||
/* Results:
|
||||
The greatest number of primes found is 70
|
||||
It was found with A = -61, B = 971
|
||||
@@ -59,4 +59,5 @@ The product of A and B is -59231
|
||||
It took an average of 14.261 milliseconds to run this problem over 100 iterations
|
||||
*/
|
||||
|
||||
#endif //PROBLEM27_HPP
|
||||
|
||||
#endif //PROBLEM27_HPP
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
//ProjectEuler/ProjectEulerCPP/headers/Problems/Problem28.hpp
|
||||
//Matthew Ellison
|
||||
// Created: 09-21-19
|
||||
//Modified: 08-28-20
|
||||
//Modified: 07-02-21
|
||||
//What is the sum of the numbers on the diagonals in a 1001 by 1001 spiral formed by starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral
|
||||
//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
|
||||
@@ -20,14 +20,12 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef PROBLEM28_HPP
|
||||
#define PROBLEM28_HPP
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "Problem.hpp"
|
||||
|
||||
@@ -50,14 +48,16 @@ public:
|
||||
virtual void solve(); //Solve the problem
|
||||
virtual void reset(); //Reset the problem so it can be run again
|
||||
//Gets
|
||||
virtual std::string getResult(); //Return a string with the solution to the problem
|
||||
virtual std::string getResult() const; //Return a string with the solution to the problem
|
||||
std::vector<std::vector<int>> getGrid() const; //Returns the grid
|
||||
uint64_t getSum() const; //Returns the sum of the diagonals
|
||||
};
|
||||
|
||||
|
||||
/* Results:
|
||||
The sum of the diagonals in the given grid is 669171001
|
||||
It took an average of 1.254 milliseconds to run this problem over 100 iterations
|
||||
*/
|
||||
|
||||
#endif //PROBLEM28_HPP
|
||||
|
||||
#endif //PROBLEM28_HPP
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
//ProjectEuler/ProjectEulerCPP/headers/Problems/Problem29.hpp
|
||||
//Matthew Ellison
|
||||
// Created: 10-06-19
|
||||
//Modified: 08-28-20
|
||||
//Modified: 07-02-21
|
||||
//How many distinct terms are in the sequence generated by a^b for 2 <= a <= 100 and 2 <= b <= 100?
|
||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/myClasses
|
||||
//This file contains a header from the gmp library. The library is used for large integers.
|
||||
//You can find more information about them at https://gmplib.org/
|
||||
//When compiling this file you need to have the gmp library installed as well as linking the libraries to your executable using the -lgmpxx and -lgmp flags
|
||||
/*
|
||||
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
|
||||
@@ -23,14 +23,12 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef PROBLEM29_HPP
|
||||
#define PROBLEM29_HPP
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <gmpxx.h>
|
||||
#include "Problem.hpp"
|
||||
@@ -41,9 +39,9 @@ private:
|
||||
//Variables
|
||||
//Static variables
|
||||
static unsigned int BOTTOM_A; //The lowest possible value for a
|
||||
static unsigned int TOP_A; //The highest possible value for a
|
||||
static unsigned int TOP_A; //The highest possible value for a
|
||||
static unsigned int BOTTOM_B; //The lowest possible value for b
|
||||
static unsigned int TOP_B; //The highest possible value for b
|
||||
static unsigned int TOP_B; //The highest possible value for b
|
||||
//Instance variables
|
||||
std::vector<mpz_class> unique; //Holds all values in powers, except repeats
|
||||
public:
|
||||
@@ -53,17 +51,20 @@ public:
|
||||
virtual void solve(); //Solve the problem
|
||||
virtual void reset(); //Reset the problem so it can be run again
|
||||
//Gets
|
||||
virtual std::string getResult(); //Return a string with the solution to the problem
|
||||
virtual std::string getResult()const; //Return a string with the solution to the problem
|
||||
unsigned int getBottomA() const; //Returns the lowest possible value for a
|
||||
unsigned int getTopA() const; //Returns the highest possible value for a
|
||||
unsigned int getTopA() const; //Returns the highest possible value for a
|
||||
unsigned int getBottomB() const; //Returns the lowest possible value for b
|
||||
unsigned int getTopB() const; //Returns the highest possible value for b
|
||||
unsigned int getTopB() const; //Returns the highest possible value for b
|
||||
std::vector<mpz_class> getUnique() const; //Returns a vector of all the unique values for a^b
|
||||
size_t getNumUnique() const; //Returns the number of unique values for a^b
|
||||
};
|
||||
|
||||
|
||||
/* Results:
|
||||
The number of unique values generated by a^b for 2 <= a <= 100 and 2 <= b <= 100 is 9183
|
||||
It took an average of 1.651 seconds to run this problem over 100 iterations
|
||||
*/
|
||||
|
||||
#endif //PROBLEM29_HPP
|
||||
|
||||
#endif //PROBLEM29_HPP
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
//ProjectEuler/ProjectEulerCPP/headers/Problems/Problem3.hpp
|
||||
//Matthew Ellison
|
||||
// Created: 09-28-18
|
||||
//Modified: 08-28-20
|
||||
//Modified: 07-02-21
|
||||
//The largest prime factor of 600851475143
|
||||
//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
|
||||
@@ -20,14 +20,13 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PROBLEM3_HPP
|
||||
#define PROBLEM3_HPP
|
||||
|
||||
|
||||
#include <vector>
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "Problem.hpp"
|
||||
|
||||
|
||||
@@ -45,15 +44,16 @@ public:
|
||||
virtual void solve(); //Solve the problem
|
||||
virtual void reset(); //Reset the problem so it can be run again
|
||||
//Gets
|
||||
virtual std::string getResult(); //Return a string with the solution to the problem
|
||||
virtual std::string getResult() const; //Return a string with the solution to the problem
|
||||
std::vector<uint64_t> getFactors() const; //Returns the list of factors of the number
|
||||
uint64_t getLargestFactor() const; //Returns the largest factor of the number
|
||||
uint64_t getGoalNumber() const; //Returns the number
|
||||
};
|
||||
|
||||
|
||||
/* Results:
|
||||
The largest factor of the number 600851475143 is 6857
|
||||
It took an average of 50.300 milliseconds to run this problem over 100 iterations
|
||||
*/
|
||||
|
||||
#endif //PROBLEM3_HPP
|
||||
|
||||
#endif //PROBLEM3_HPP
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
//ProjectEuler/ProjectEulerCPP/headers/Problems/Problem30.hpp
|
||||
//Matthew Ellison
|
||||
// Created: 10-27-19
|
||||
//Modified: 08-28-20
|
||||
//Modified: 07-02-21
|
||||
//Find the sum of all the numbers that can be written as the sum of the fifth powers of their digits.
|
||||
//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
|
||||
@@ -20,13 +20,12 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PROBLEM30_HPP
|
||||
#define PROBLEM30_HPP
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "Problem.hpp"
|
||||
|
||||
@@ -51,7 +50,7 @@ public:
|
||||
virtual void solve(); //Solve the problem
|
||||
virtual void reset(); //Reset the problem so it can be run again
|
||||
//Gets
|
||||
virtual std::string getResult(); //Return a string with the solution to the problem
|
||||
virtual std::string getResult() const; //Return a string with the solution to the problem
|
||||
uint64_t getTopNum() const; //This returns the top number to be checked
|
||||
std::vector<uint64_t> getListOfSumOfFifths() const; //This returns a copy of the vector holding all the numbers that are the sum of the fifth power of their digits
|
||||
uint64_t getSumOfList() const; //This returns the sum of all entries in sumOfFifthNumbers
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
//ProjectEuler/ProjectEulerCPP/headers/Problems/Problem31.hpp
|
||||
//Matthew Ellison
|
||||
// Created: 06-19-20
|
||||
//Modified: 08-28-20
|
||||
//Modified: 07-02-21
|
||||
//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
|
||||
/*
|
||||
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
|
||||
@@ -20,13 +20,11 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PROBLEM31_HPP
|
||||
#define PROBLEM31_HPP
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "Problem.hpp"
|
||||
|
||||
|
||||
@@ -44,7 +42,7 @@ public:
|
||||
virtual void solve(); //Solve the problem
|
||||
virtual void reset(); //Reset the problem so it can be run again
|
||||
//Gets
|
||||
virtual std::string getResult(); //Return a string with the solution to the problem
|
||||
virtual std::string getResult() const; //Return a string with the solution to the problem
|
||||
int getPermutations() const; //Returns the number of correct permutations of the coins
|
||||
};
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//ProjectEuler/ProjectEulerCPP/headers/Problems/Problem32.hpp
|
||||
//Matthew Ellison
|
||||
// Created: 07-27-20
|
||||
//Modified: 08-28-20
|
||||
//Modified: 07-02-21
|
||||
//Find the sum of all products whose multiplicand/multiplier/product identity can be written as a 1 through 9 pandigital.
|
||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/myClasses
|
||||
/*
|
||||
@@ -20,7 +20,6 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PROBLEM32_HPP
|
||||
#define PROBLEM32_HPP
|
||||
|
||||
@@ -69,8 +68,8 @@ public:
|
||||
void solve(); //Solve the problem
|
||||
void reset(); //Reset the problem so it can be run again
|
||||
//Gets
|
||||
virtual std::string getResult(); //Return a string with the solution to the problem
|
||||
int64_t getSumOfPandigitals(); //Returns the sum of the pandigitals
|
||||
virtual std::string getResult() const; //Return a string with the solution to the problem
|
||||
int64_t getSumOfPandigitals() const; //Returns the sum of the pandigitals
|
||||
};
|
||||
|
||||
/* Results:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//ProjectEuler/ProjectEulerCPP/headers/Problems/Problem33.hpp
|
||||
//Matthew Ellison
|
||||
// Created: 02-05-2021
|
||||
//Modified: 02-05-2021
|
||||
// Created: 02-05-21
|
||||
//Modified: 07-03-21
|
||||
/*
|
||||
The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplify it may incorrectly believe that 49/98 = 4/8, which is correct, is obtained by cancelling the 9s
|
||||
We shall consider fractions like, 30/50 = 3/5, to be trivial examples
|
||||
@@ -25,12 +25,10 @@ If the product of these four fractions is given in its lowest common terms, find
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PROBLEM33_HPP
|
||||
#define PROBLEM33_HPP
|
||||
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "Problem.hpp"
|
||||
@@ -40,14 +38,14 @@ class Problem33: public Problem{
|
||||
private:
|
||||
//Variables
|
||||
//Static variables
|
||||
static int MIN_NUMERATOR; //The lowest the numerator can be
|
||||
static int MAX_NUMERATOR; //The highest the numerator can be
|
||||
static int MIN_NUMERATOR; //The lowest the numerator can be
|
||||
static int MAX_NUMERATOR; //The highest the numerator can be
|
||||
static int MIN_DENOMINATOR; //The lowest the denominator can be
|
||||
static int MAX_DENOMINATOR; //The highest the denominator can be
|
||||
//Instance variables
|
||||
std::vector<int> numerators; //Holds the numerators that were found
|
||||
std::vector<int> denominators; //Holds the denominators that were found
|
||||
int prodDenominator; //Holds the answer to the question
|
||||
int prodDenominator; //Holds the answer to the question
|
||||
public:
|
||||
//Constructor
|
||||
Problem33();
|
||||
@@ -55,15 +53,17 @@ public:
|
||||
virtual void solve(); //Solve the problem
|
||||
virtual void reset(); //Reset the problem so it can be run again
|
||||
//Gets
|
||||
virtual std::string getResult(); //Return a string with the solution to the problem
|
||||
std::vector<int> getNumerators(); //Returns the list of numerators
|
||||
std::vector<int> getDenominators(); //Returns the list of denominators
|
||||
int getProdDenominator(); //Returns the answer to the question
|
||||
virtual std::string getResult() const; //Return a string with the solution to the problem
|
||||
std::vector<int> getNumerators() const; //Returns the list of numerators
|
||||
std::vector<int> getDenominators() const; //Returns the list of denominators
|
||||
int getProdDenominator() const; //Returns the answer to the question
|
||||
};
|
||||
|
||||
|
||||
/* Results:
|
||||
The denominator of the product is 100
|
||||
It took an average of 69.741 microseconds to run this problem over 100 iterations
|
||||
*/
|
||||
|
||||
#endif //PROBLEM33_HPP
|
||||
|
||||
#endif //PROBLEM33_HPP
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//ProjectEuler/ProjectEulerCPP/headers/Problems/Problem34.hpp
|
||||
//Matthew Ellison
|
||||
// Created: 06-01-21
|
||||
//Modified: 06-01-21
|
||||
//Modified: 07-02-21
|
||||
//Find the sum of all numbers which are equal to the sum of the factorial of their digits
|
||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/myClasses
|
||||
/*
|
||||
@@ -20,7 +20,6 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PROBLEM34_HPP
|
||||
#define PROBLEM34_HPP
|
||||
|
||||
@@ -45,14 +44,16 @@ public:
|
||||
virtual void solve(); //Solve the problem
|
||||
virtual void reset(); //Reset the problem so it can be run again
|
||||
//Gets
|
||||
virtual std::string getResult(); //Return a string with the solution to the problem
|
||||
std::vector<int> getFactorials(); //Returns the list of factorials from 0-9
|
||||
int getSum(); //Returns the sum of all numbers equal to the sum of their digit's factorials
|
||||
virtual std::string getResult() const; //Return a string with the solution to the problem
|
||||
std::vector<int> getFactorials() const; //Returns the list of factorials from 0-9
|
||||
int getSum() const; //Returns the sum of all numbers equal to the sum of their digit's factorials
|
||||
};
|
||||
|
||||
|
||||
/* Results:
|
||||
The sum of all numbers that are the sum of their digit's factorials is 40730
|
||||
It took an average of 15.181 milliseconds to run this problem over 100 iterations
|
||||
*/
|
||||
|
||||
#endif //PROBLEM34_HPP
|
||||
|
||||
#endif //PROBLEM34_HPP
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//ProjectEuler/ProjectEulerCPP/headers/Problems/Problem35.hpp
|
||||
//Matthew Ellison
|
||||
// Created: 06-02-21
|
||||
//Modified: 06-02-21
|
||||
//Modified: 07-02-21
|
||||
//How many circular primes are there below one million?
|
||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/myClasses
|
||||
/*
|
||||
@@ -20,7 +20,6 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PROBLEM35_HPP
|
||||
#define PROBLEM35_HPP
|
||||
|
||||
@@ -47,15 +46,17 @@ public:
|
||||
virtual void solve(); //Solve the problem
|
||||
virtual void reset(); //Reset the problem so it can be run again
|
||||
//Gets
|
||||
virtual std::string getResult(); //Returns a string with the solution to the problem
|
||||
std::vector<int> getPrimes(); //Returns the vector of primes < MAX_NUM
|
||||
std::vector<int> getCircularPrimes(); //Returns the vector of circular primes < MAX_NUM
|
||||
int getNumCircularPrimes(); //Returns the number of circular primes
|
||||
virtual std::string getResult() const; //Returns a string with the solution to the problem
|
||||
std::vector<int> getPrimes() const; //Returns the vector of primes < MAX_NUM
|
||||
std::vector<int> getCircularPrimes() const; //Returns the vector of circular primes < MAX_NUM
|
||||
int getNumCircularPrimes() const; //Returns the number of circular primes
|
||||
};
|
||||
|
||||
|
||||
/* Results:
|
||||
The number of all circular prime numbers under 999999 is 55
|
||||
It took an average of 2.618 seconds to run this problem over 100 iterations
|
||||
*/
|
||||
|
||||
#endif //PROBLEM35_HPP
|
||||
|
||||
#endif //PROBLEM35_HPP
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//ProjectEuler/ProjectEulerCPP/headers/Problems/Problem36.hpp
|
||||
//Matthew Ellison
|
||||
// Created: 06-29-21
|
||||
//Modified: 06-29-21
|
||||
//Modified: 07-02-21
|
||||
//Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2.
|
||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/myClasses
|
||||
/*
|
||||
@@ -20,7 +20,6 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PROBLEM36_HPP
|
||||
#define PROBLEM36_HPP
|
||||
|
||||
@@ -28,7 +27,6 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "Problem.hpp"
|
||||
#include "Algorithms.hpp"
|
||||
|
||||
|
||||
class Problem36 : public Problem{
|
||||
@@ -47,11 +45,12 @@ public:
|
||||
virtual void solve(); //Solve the problem
|
||||
virtual void reset(); //Reset the problem so it can be run again
|
||||
//Gets
|
||||
virtual std::string getResult(); //Returns a string with the solution to the problem
|
||||
std::vector<int> getPalindromes(); //Return the vector of palindromes < MAX_NUM
|
||||
int getSumOfPalindromes(); //Return the sum of all elements in the vector of palindromes
|
||||
virtual std::string getResult() const; //Returns a string with the solution to the problem
|
||||
std::vector<int> getPalindromes() const; //Return the vector of palindromes < MAX_NUM
|
||||
int getSumOfPalindromes() const; //Return the sum of all elements in the vector of palindromes
|
||||
};
|
||||
|
||||
|
||||
/* Results:
|
||||
The sum of all base 10 and base 2 palindromic numbers < 999999 is 872187
|
||||
It took an average of 22.578 milliseconds to run this problem over 100 iterations
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//ProjectEuler/ProjectEulerCPP/headers/Problems/Problem37.hpp
|
||||
//Matthew Ellison
|
||||
// Created: 06-30-21
|
||||
//Modified: 06-30-21
|
||||
//Modified: 07-02-21
|
||||
//Find the sum of the only eleven primes that are both truncatable from left to right and right to left (2, 3, 5, and 7 are not counted).
|
||||
//Unless otherwise listed all non-standard includes are my own creation and available from https://bibucket.org/Mattrixwv/myClasses
|
||||
/*
|
||||
@@ -20,11 +20,11 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PROBLEM37_HPP
|
||||
#define PROBLEM37_HPP
|
||||
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "Problem.hpp"
|
||||
@@ -46,11 +46,12 @@ public:
|
||||
virtual void solve(); //Solve the problem
|
||||
virtual void reset(); //Reset the problem so it can be run again
|
||||
//Gets
|
||||
virtual std::string getResult(); //Returns a string with the solution to the problem
|
||||
std::vector<uint64_t> getTruncatablePrimes(); //Returns the list of primes that can be truncated
|
||||
uint64_t getSumOfPrimes(); //Get the sum of all primes in truncPrimes
|
||||
virtual std::string getResult() const; //Returns a string with the solution to the problem
|
||||
std::vector<uint64_t> getTruncatablePrimes() const; //Returns the list of primes that can be truncated
|
||||
uint64_t getSumOfPrimes() const; //Get the sum of all primes in truncPrimes
|
||||
};
|
||||
|
||||
|
||||
/* Results:
|
||||
The sum of all left and right truncatable primes is 748317
|
||||
It took an average of 63.831 milliseconds to run this problem over 100 iterations
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
//ProjectEuler/ProjectEulerCPP/headers/Problems/Problem4.hpp
|
||||
//Matthew Ellison
|
||||
// Created: 09-28-18
|
||||
//Modified: 08-28-20
|
||||
//Modified: 07-02-21
|
||||
//Find the largest palindrome made from the product of two 3-digit numbers
|
||||
//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
|
||||
@@ -20,13 +20,13 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PROBLEM4_HPP
|
||||
#define PROBLEM4_HPP
|
||||
|
||||
|
||||
#include <vector>
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "Problem.hpp"
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ public:
|
||||
virtual void solve(); //Solve the problem
|
||||
virtual void reset(); //Reset the problem so it can be run again
|
||||
//Gets
|
||||
virtual std::string getResult(); //Return a string with the solution to the problem
|
||||
virtual std::string getResult() const; //Return a string with the solution to the problem
|
||||
std::vector<uint64_t> getPalindromes() const; //Returns the list of all palindromes
|
||||
uint64_t getLargestPalindrome() const; //Returns the largest palindrome
|
||||
};
|
||||
@@ -56,4 +56,5 @@ The largest palindrome is 906609
|
||||
It took an average of 36.525 milliseconds to run this problem over 100 iterations
|
||||
*/
|
||||
|
||||
#endif //PROBLEM4_HPP
|
||||
|
||||
#endif //PROBLEM4_HPP
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
//ProjectEuler/ProjectEulerCPP/headers/Problems/Problem5.hpp
|
||||
//Matthew Ellison
|
||||
// Created: 09-28-18
|
||||
//Modified: 08-28-20
|
||||
//Modified: 07-02-21
|
||||
//What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
|
||||
//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
|
||||
@@ -20,13 +20,10 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PROBLEM5_HPP
|
||||
#define PROBLEM5_HPP
|
||||
|
||||
|
||||
#include <vector>
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include "Problem.hpp"
|
||||
|
||||
@@ -43,13 +40,15 @@ public:
|
||||
virtual void solve(); //Solve the problem
|
||||
virtual void reset(); //Reset the problem so it can be run again
|
||||
//Gets
|
||||
virtual std::string getResult(); //Return a string with the solution to the problem
|
||||
virtual std::string getResult() const; //Return a string with the solution to the problem
|
||||
int getNumber() const; //Returns the requested number
|
||||
};
|
||||
|
||||
|
||||
/* Results:
|
||||
The smallest positive number evenly divisible by all numbers 1-20 is 232792560
|
||||
It took an average of 1.928 seconds to run this problem over 100 iterations
|
||||
It took an average of 1.802 seconds to run this problem over 100 iterations
|
||||
*/
|
||||
|
||||
#endif //PROBLEM5_HPP
|
||||
|
||||
#endif //PROBLEM5_HPP
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
//ProjectEuler/ProjectEulerCPP/headers/Problems/Problem6.hpp
|
||||
//Matthew Ellison
|
||||
// Created: 09-28-18
|
||||
//Modified: 08-28-20
|
||||
//Modified: 07-02-21
|
||||
//Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
|
||||
//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
|
||||
@@ -20,7 +20,6 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PROBLEM6_HPP
|
||||
#define PROBLEM6_HPP
|
||||
|
||||
@@ -46,15 +45,17 @@ public:
|
||||
virtual void solve(); //Solve the problem
|
||||
virtual void reset(); //Reset the problem so it can be run again
|
||||
//Gets
|
||||
virtual std::string getResult(); //Return a string with the solution to the problem
|
||||
virtual std::string getResult() const; //Return a string with the solution to the problem
|
||||
uint64_t getSumOfSquares() const; //Returns the sum of all the squares
|
||||
uint64_t getSquareOfSum() const; //Returns the square of all of the sums
|
||||
uint64_t getDifference() const; //Returns the requested difference
|
||||
};
|
||||
|
||||
/* Result
|
||||
|
||||
/* Result:
|
||||
The difference between the sum of the squares and the square of the sum of all numbers from 1-100 is 25164150
|
||||
It took an average of 76.000 nanoseconds to run this problem over 100 iterations
|
||||
*/
|
||||
|
||||
#endif //PROBLEM6_HPP
|
||||
|
||||
#endif //PROBLEM6_HPP
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//ProjectEuler/ProjectEulerCPP/headers/Problems/Problem67.hpp
|
||||
//Matthew Ellison
|
||||
// Created: 11-02-18
|
||||
//Modified: 07-09-20
|
||||
//Modified: 07-02-21
|
||||
//The way to do this is using a breadth first search
|
||||
/*
|
||||
Find the maximum total from top to bottom
|
||||
@@ -108,7 +108,7 @@ Find the maximum total from top to bottom
|
||||
*/
|
||||
//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
|
||||
@@ -123,11 +123,11 @@ Find the maximum total from top to bottom
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PROBLEM67_HPP
|
||||
#define PROBLEM67_HPP
|
||||
|
||||
|
||||
#include "Problem67.hpp"
|
||||
#include "Problem18.hpp"
|
||||
|
||||
|
||||
@@ -136,15 +136,14 @@ class Problem67 : public Problem18{
|
||||
private:
|
||||
void setupList();
|
||||
public:
|
||||
Problem67() : Problem18(){
|
||||
list.clear();
|
||||
setupList();
|
||||
}
|
||||
Problem67();
|
||||
};
|
||||
|
||||
|
||||
/* Results:
|
||||
The value of the longest path is 7273
|
||||
It took an average of 366.373 milliseconds to run this problem over 100 iterations
|
||||
*/
|
||||
|
||||
#endif //PROBLEM67_HPP
|
||||
|
||||
#endif //PROBLEM67_HPP
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
//ProjectEuler/ProjectEulerCPP/headers/Problems/Problem7.hpp
|
||||
//Matthew Ellison
|
||||
// Created: 09-28-18
|
||||
//Modified: 08-28-20
|
||||
//Modified: 07-02-21
|
||||
//What is the 10001th prime number?
|
||||
//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
|
||||
@@ -20,14 +20,13 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PROBLEM7_HPP
|
||||
#define PROBLEM7_HPP
|
||||
|
||||
|
||||
#include <vector>
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "Problem.hpp"
|
||||
|
||||
|
||||
@@ -45,13 +44,15 @@ public:
|
||||
virtual void solve(); //Solve the problem
|
||||
virtual void reset(); //Reset the problem so it can be run again
|
||||
//Gets
|
||||
virtual std::string getResult(); //Return a string with the solution to the problem
|
||||
virtual std::string getResult() const; //Return a string with the solution to the problem
|
||||
uint64_t getPrime() const; //Returns the requested prime number
|
||||
};
|
||||
|
||||
/* Results
|
||||
|
||||
/* Results:
|
||||
The 10001th prime number is 104743
|
||||
It took an average of 3.864 milliseconds to run this problem over 100 iterations
|
||||
*/
|
||||
|
||||
#endif //PROBLEM7_HPP
|
||||
|
||||
#endif //PROBLEM7_HPP
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//ProjectEuler/ProjectEulerCPP/headers/Problems/Problem8.hpp
|
||||
//Matthew Ellison
|
||||
// Created: 09-28-18
|
||||
//Modified: 08-28-20
|
||||
//Modified: 07-02-21
|
||||
//Find the thirteen adjacent digits in the 1000-digit number that have the greatest product. What is the value of this product?
|
||||
/*
|
||||
73167176531330624919225119674426574742355349194934
|
||||
@@ -27,7 +27,7 @@
|
||||
*/
|
||||
//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
|
||||
@@ -42,14 +42,12 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PROBLEM8_HPP
|
||||
#define PROBLEM8_HPP
|
||||
|
||||
|
||||
#include <cinttypes>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "Problem.hpp"
|
||||
|
||||
|
||||
@@ -68,16 +66,17 @@ public:
|
||||
virtual void solve(); //Solve the problem
|
||||
virtual void reset(); //Reset the problem so it can be run again
|
||||
//Gets
|
||||
virtual std::string getResult(); //Return a string with the solution to the problem
|
||||
virtual std::string getResult() const; //Return a string with the solution to the problem
|
||||
std::string getLargestNums() const; //Returns the string of numbers that produces the largest product
|
||||
uint64_t getLargestProduct() const; //Returns the requested product
|
||||
};
|
||||
|
||||
|
||||
/* Results
|
||||
/* Results:
|
||||
The greatest product is 23514624000
|
||||
The numbers are 5576689664895
|
||||
It took an average of 129.024 microseconds to run this problem over 100 iterations
|
||||
*/
|
||||
|
||||
#endif //PROBLEM8_HPP
|
||||
|
||||
#endif //PROBLEM8_HPP
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
//ProjectEuler/ProjectEulerCPP/headers/Problems/Problem9.hpp
|
||||
//Matthew Ellison
|
||||
// Created: 09-28-18
|
||||
//Modified: 08-28-20
|
||||
//Modified: 07-02-21
|
||||
//There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product of abc.
|
||||
//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
|
||||
@@ -20,12 +20,10 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PROBLEM9_HPP
|
||||
#define PROBLEM9_HPP
|
||||
|
||||
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
#include "Problem.hpp"
|
||||
|
||||
@@ -47,17 +45,19 @@ public:
|
||||
virtual void solve(); //Solve the problem
|
||||
virtual void reset(); //Reset the problem so it can be run again
|
||||
//Gets
|
||||
virtual std::string getResult(); //Return a string with the solution to the problem
|
||||
virtual std::string getResult() const; //Return a string with the solution to the problem
|
||||
int getSideA() const; //Returns the length of the first side
|
||||
int getSideB() const; //Returns the length of the second side
|
||||
int getSideC() const; //Returns the length of the hyp
|
||||
int getProduct() const; //Returns the product of the 3 sides
|
||||
};
|
||||
|
||||
|
||||
/* Results:
|
||||
The Pythagorean triplet is 200 375 425
|
||||
The numbers' product is 31875000
|
||||
It took an average of 154.595 microseconds to run this problem over 100 iterations
|
||||
*/
|
||||
|
||||
#endif //PROBLEM9_HPP
|
||||
|
||||
#endif //PROBLEM9_HPP
|
||||
|
||||
Reference in New Issue
Block a user