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/Problem1.py
#Matthew Ellison
# Created: 01-26-19
#Modified: 10-29-20
#Modified: 10-30-20
#What is the sum of all the multiples of 3 or 5 that are less than 1000
#Unless otherwise listed, all of my non-standard imports can be gotten from my pyClasses repository at https://bitbucket.org/Mattrixwv/pyClasses
"""
@@ -60,13 +60,14 @@ class Problem1(Problem):
def reset(self):
super().reset()
self.fullSum = 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 "The sum of all numbers < " + str(self.__topNum + 1) + " is " + str(self.fullSum)
#Gets
return f"The sum of all numbers < {self.__topNum + 1} is {self.fullSum}"
#Returns the requested sum
def getSum(self) -> int:
#If the problem hasn't been solved throw an exception
@@ -80,15 +81,6 @@ class Problem1(Problem):
return int((numTerms / 2) * (multiple + (numTerms * multiple)))
#If you are running this file, automatically start the correct function
if(__name__ == "__main__"):
problem = Problem1()
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 sum of all numbers < 1000 is 233168
It took an average of 2.293 microseconds to run this problem through 100 iterations