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/Problem23.py
#Matthew Ellison
# Created: 03-22-19
#Modified: 07-19-20
#Modified: 10-30-20
#Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers
#All of my 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
import Algorithms
@@ -50,7 +49,6 @@ class Problem23(Problem):
#Start the timer
self.timer.start()
#Get the sum of the divisors of all numbers < __maxNum
for cnt in range(1, self.__maxNum):
div = Algorithms.getDivisors(cnt)
@@ -70,13 +68,9 @@ class Problem23(Problem):
if(not self.isSum(abund, cnt)):
self.sum += cnt
#Stop the timer
self.timer.stop()
#Save the results
self.result = "The answer is " + str(self.sum)
#Throw a flag to show the problem is solved
self.solved = True
#Reserve the size of the array to speed up insertion
@@ -106,6 +100,12 @@ class Problem23(Problem):
self.sum = 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"The answer is {self.sum}"
#Returns the sum of the numbers asked for
def getSum(self) -> int:
#If the problem hasn't been solved throw an exception
@@ -114,14 +114,6 @@ class Problem23(Problem):
return self.sum
if __name__ == "__main__":
problem = Problem23()
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 answer is 4179871
It took an average of 24.184 minutes to run this problem through 10 iterations