Updated all problems to use fstrings and results()

This commit is contained in:
2020-10-30 16:20:39 -04:00
parent ad458278d4
commit 46216a2807
33 changed files with 280 additions and 452 deletions

View File

@@ -1,7 +1,7 @@
#ProjectEuler/Python/Problem29.py
#Matthew Ellison
# Created: 10-10-19
#Modified: 07-19-20
#Modified: 10-30-20
#How many distinct terms are in the sequence generated by a^b for 2 <= a <= 100 and 2 <= b <= 100?
#Unless otherwise listed, all of my non-standard imports can be gotten from my pyClasses repository at https://bitbucket.org/Mattrixwv/pyClasses
"""
@@ -23,7 +23,6 @@
from Problems.Problem import Problem
from Stopwatch import Stopwatch
from Unsolved import Unsolved
@@ -63,17 +62,21 @@ class Problem29(Problem):
#Stop the timer
self.timer.stop()
#Print the results
self.result = "The number of unique values generated by a^b for " + str(self.__bottomA) + " <= a < = " + str(self.__topA) + " and " + str(self.__bottomB) + " <= b <= " + str(self.__topB) + " is " + str(len(self.unique))
#Throw a flag to show the problem is solved
self.solved = True
#Reset the problem so it can be run again
def reset(self):
super().reset()
self.unique.clear()
#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"The number of unique values generated by a^b for {self.__bottomA} <= a < = {self.__topA} and {self.__bottomB} <= b <= {self.__topB} is {len(self.unique)}"
#Returns the lowest possible value for a
def getBottomA(self):
#If the problem hasn't been solved throw an exception
@@ -106,15 +109,6 @@ class Problem29(Problem):
return self.unique
#This calls the appropriate functions if the script is called stand alone
if __name__ == "__main__":
problem = Problem29()
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:
The number of unique values generated by a^b for 2 <= a < = 100 and 2 <= b <= 100 is 9183
It took an average of 304.306 milliseconds to run this problem through 100 iterations