mirror of
https://bitbucket.org/Mattrixwv/projecteulerpython.git
synced 2025-12-06 17:43:58 -05:00
Updated all problems to use fstrings and results()
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#ProjectEuler/ProjectEulerPython/Problems/Problem32.py
|
||||
#Matthew Ellison
|
||||
# Created: 07-28-20
|
||||
#Modified: 07-28-20
|
||||
#Modified: 10-30-20
|
||||
#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
|
||||
"""
|
||||
@@ -23,9 +23,7 @@
|
||||
|
||||
|
||||
from Problems.Problem import Problem
|
||||
from Stopwatch import Stopwatch
|
||||
from Unsolved import Unsolved
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
class Problem32(Problem):
|
||||
@@ -87,9 +85,6 @@ class Problem32(Problem):
|
||||
#Stop the timer
|
||||
self.timer.stop()
|
||||
|
||||
#Save the results
|
||||
self.result = "There are " + str(len(self.listOfProducts)) + " unique 1-9 pandigitals\nThe sum of the products of these pandigitals is " + str(self.sumOfPandigitals)
|
||||
|
||||
#Throw a flag to show the problem is solved
|
||||
self.solved = True
|
||||
|
||||
@@ -115,6 +110,12 @@ class Problem32(Problem):
|
||||
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")
|
||||
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
|
||||
@@ -122,15 +123,6 @@ class Problem32(Problem):
|
||||
raise Unsolved("You must solve the problem before can you see the sum of the pandigitals")
|
||||
return self.sumOfPandigitals
|
||||
|
||||
#This calls the appropriate functions if the script is called stand alone
|
||||
if __name__ == "__main__":
|
||||
problem = Problem32()
|
||||
print(problem.getDescription()) #Print the description
|
||||
problem.solve() #Call the function that answers the problem
|
||||
#Print the results
|
||||
print(problem.getResult())
|
||||
print("It took " + problem.getTime() + " to solve this algorithm")
|
||||
|
||||
|
||||
""" Results:
|
||||
There are 7 unique 1-9 pandigitals
|
||||
|
||||
Reference in New Issue
Block a user