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/Problem3.py
#Matthew Ellison
# Created: 01-27-19
#Modified: 10-29-20
#Modified: 10-30-20
#The largest prime factor of 600851475143
#Unless otherwise listed, all of my non-standard imports can be gotten from my pyClasses repository at https://bitbucket.org/Mattrixwv/pyClasses
"""
@@ -27,7 +27,6 @@ from Algorithms import getFactors
from Unsolved import Unsolved
class Problem3(Problem):
#Variables
__goalNumber = 600851475143
@@ -62,13 +61,14 @@ class Problem3(Problem):
def reset(self):
super().reset()
self.factors.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 "The largest prime factor of " + str(self.__goalNumber) + " is " + str(self.factors[(len(self.factors) - 1)])
#Gets
return f"The largest prime factor of {self.__goalNumber} is {self.factors[(len(self.factors) - 1)]}"
#Returns the list of factors of the number
def getFactors(self) -> list:
#If the problem hasn't been solved throw an exceptions
@@ -86,15 +86,6 @@ class Problem3(Problem):
return self.__goalNumber
#If you are running this file, automatically start the correct function
if __name__ == '__main__':
problem = Problem3()
print(problem.getDescription()) #Print the description of the problem
problem.solve() #Solve the problem
#Print the results
print(problem.getResult())
print("It took " + problem.getTime() + " to solve this algorithm")
"""Results:
The largest prime factor of 600851475143 is 6857
It took an average of 2.084 seconds to run this problem through 100 iterations