Added solution to problem 38

This commit is contained in:
2021-10-10 23:00:10 -04:00
parent 6e4dd45702
commit 82634c02ed
4 changed files with 159 additions and 2 deletions

View File

@@ -62,6 +62,7 @@
#include "Problems/Problem35.hpp"
#include "Problems/Problem36.hpp"
#include "Problems/Problem37.hpp"
#include "Problems/Problem38.hpp"
#include "Problems/Problem67.hpp"
@@ -69,7 +70,7 @@
std::vector<unsigned int> PROBLEM_NUMBERS = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
31, 32, 33, 34, 35, 36, 37, 67};
31, 32, 33, 34, 35, 36, 37, 38, 67};
//This function returns a pointer to a problem of type number
Problem* getProblem(unsigned int problemNumber){
@@ -114,6 +115,7 @@ Problem* getProblem(unsigned int problemNumber){
case 35 : problem = new Problem35; break;
case 36 : problem = new Problem36; break;
case 37 : problem = new Problem37; break;
case 38 : problem = new Problem38; break;
case 67 : problem = new Problem67; break;
}

View File

@@ -0,0 +1,51 @@
//ProjectEuler/ProjectEulerCPP/headers/Problems/Problem38.hpp
//Matthew Ellison
// Created: 10-10-21
//Modified: 10-10-21
//What is the largest 1-9 pandigital number that can be formed as the concatenated product of an integer with 1, 2, ... n where n > 1
/*
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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
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/>.
*/
#pragma once
#include <cinttypes>
#include <string>
#include "Problem.hpp"
class Problem38 : public Problem{
private:
//Variables
//Static variables
static int HIGHEST_POSSIBLE_NUM; //The highest number that needs to be checked for a 1-9 pandigital
//Instance variables
uint64_t largestNum;
uint64_t pandigital;
//Functions
std::string executeFormula(int num); //Take the number and add its multiples to a string to return
public:
//Functions
//Constructor
Problem38();
//Operational functions
virtual void solve(); //Solve the problem
virtual void reset(); //Reset the problem so it can be run again
//Gets
virtual std::string getResult() const; //Returns a string with the solution to the problem
uint64_t getLargestNum() const; //Returns the largest number
uint64_t getPandigital() const; //Returns the pandigital of the number
};