Updated to use new library layout

This commit is contained in:
2021-07-24 16:13:05 -04:00
parent d18b3fa9f6
commit 84555edd31
39 changed files with 515 additions and 709 deletions

View File

@@ -1,11 +1,11 @@
#ProjectEuler/ProjectEulerPython/Problems/Problem32.py
#Matthew Ellison
# Created: 07-28-20
#Modified: 10-30-20
#Modified: 07-24-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 of my non-standard imports can be gotten from my pyClasses repository at https://bitbucket.org/Mattrixwv/pyClasses
"""
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,24 +23,23 @@
from Problems.Problem import Problem
from Unsolved import Unsolved
class Problem32(Problem):
#Structures
class ProductSet:
def __init__(self, multiplicand: int, multiplier: int):
def __init__(self, multiplicand: int, multiplier: int) -> None:
self.multiplicand = multiplicand
self.multiplier = multiplier
def getProduct(self) -> int:
return (self.multiplicand * self.multiplier)
def getNumString(self) -> str:
return (str(self.multiplicand) + str(self.multiplier) + str(self.getProduct()))
def __str__(self):
def __str__(self) -> str:
return (str(self.multiplicand) + " x " + str(self.multiplier) + " = " + str(self.getProduct()))
def __repr__(self):
def __repr__(self) -> str:
return self.__str__()
def __eq__(self, secondSet):
def __eq__(self, secondSet) -> bool:
return (self.getProduct() == secondSet.getProduct())
#Variables
@@ -50,14 +49,14 @@ class Problem32(Problem):
#Functions
#Constructor
def __init__(self):
def __init__(self) -> None:
super().__init__("Find the sum of all products whose multiplicand/multiplier/product identity can be written as a 1 through 9 pandigital.")
self.listOfProducts = [] #The list of unique products that are 1-9 pandigital
self.sumOfPandigitals = 0 #The sum of the products of the pandigital numbers
#Operational functions
#Solve the problem
def solve(self):
def solve(self) -> None:
#If the problem has already been solved do nothing and end the function
if(self.solved):
return
@@ -65,6 +64,7 @@ class Problem32(Problem):
#Start the timer
self.timer.start()
#Create the multiplicand and start working your way up
for multiplicand in range(1, self.__topMultiplicand + 1):
#Run through all possible multipliers
@@ -82,6 +82,7 @@ class Problem32(Problem):
for prod in self.listOfProducts:
self.sumOfPandigitals += prod.getProduct()
#Stop the timer
self.timer.stop()
@@ -104,23 +105,19 @@ class Problem32(Problem):
return True
#Reset the problem so it can be run again
def reset(self):
def reset(self) -> None:
super().reset()
self.listOfProducts.clear()
self.sumOfPandigitals = 0
#Gets
#Returns the result of solving the problem
def getResult(self):
#If the problem hasn't been solved throw an exception
if(not self.solved):
raise Unsolved("You must solve the problem before you can see the result")
def getResult(self) -> str:
self.solvedCheck("result")
return f"There are {self.listOfProducts} unique 1-9 pandigitals\nThe sum of the products of these pandigitals is {self.sumOfPandigitals}"
#Returns the sum of the pandigitals
def getSumOfPandigitals(self):
#If the problem hasn't been solved throw an exception
if(not self.solved):
raise Unsolved("You must solve the problem before can you see the sum of the pandigitals")
def getSumOfPandigitals(self) -> int:
self.solvedCheck("sum of the pandigitals")
return self.sumOfPandigitals