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/Problem27.py
#Matthew Ellison
# Created: 09-15-19
#Modified: 07-19-20
#Modified: 10-30-20
#Find the product of the coefficients, |a| < 1000 and |b| <= 1000, for the quadratic expression that produces the maximum number of primes for consecutive values of n, starting with n=0.
#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
import Algorithms
@@ -78,6 +77,7 @@ class Problem27(Problem):
#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()
@@ -87,18 +87,28 @@ class Problem27(Problem):
self.primes.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 greatest number of primes found is {self.topN}\n" \
f"It was found with A = {self.topA}, B = {self.topB}\n" \
f"The product of A and B is {self.topA * self.topB}"
#Returns the top A that was generated
def getTopA(self) -> int:
#If the problem hasn't been solved throw an exception
if(not self.solved):
raise Unsolved("You must solve the problem before can you see the top A")
return self.topA
#Returns the top B that was generated
def getTopB(self) -> int:
#If the problem hasn't been solved throw an exception
if(not self.solved):
raise Unsolved("You must solve the problem before can you see the top B")
return self.topA
#Returns the top N that was generated
def getTopN(self) -> int:
#If the problem hasn't been solved throw an exception
@@ -107,15 +117,6 @@ class Problem27(Problem):
return self.topA
#This calls the appropriate functions if the script is called stand alone
if __name__ == "__main__":
problem = Problem27()
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 greatest number of primes found is 70
It was found with A = -61, B = 971