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/Problem11.py
#Matthew Ellison
# Created: 01-31-19
#Modified: 07-18-20
#Modified: 10-30-20
#What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the 20×20 grid?
"""
08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08
@@ -45,7 +45,6 @@
from Problems.Problem import Problem
from Stopwatch import Stopwatch
from Unsolved import Unsolved
from Algorithms import prod
@@ -153,17 +152,21 @@ class Problem11(Problem):
#Stop the timer
self.timer.stop()
#Save the results
self.result = "The greatest product of 3 numbers in a line is " + str(prod(self.greatestProduct))
#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.greatestProduct.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 product of 3 numbers in a line is {prod(self.greatestProduct)}"
#Returns the numbers that were being searched
def getNumbers(self) -> list:
#If the problem hasn't been solved throw an exception
@@ -177,14 +180,6 @@ class Problem11(Problem):
raise Unsolved("You must solve the problem before you can get the product")
return prod(self.greatestProduct)
#If you are running this file, automatically start the correct function
if __name__ == "__main__":
problem = Problem11()
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 greatest product of 3 numbers in a line is 70600674