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/Problem67.py
#Matthew Ellison
# Created: 03-26-19
#Modified: 07-19-20
#Modified: 10-30-20
#Find the maximum total from top to bottom
"""
59
@@ -125,7 +125,6 @@
from Problems.Problem import Problem
from Stopwatch import Stopwatch
from Unsolved import Unsolved
from collections import namedtuple
@@ -298,9 +297,6 @@ class Problem67(Problem):
#Stop the timer
self.timer.stop()
#Save the results
self.result = "The value of the longest path is " + str(self.actualTotal)
#Throw a flag to show the problem is solved
self.solved = True
@@ -309,6 +305,7 @@ class Problem67(Problem):
for rowCnt in range(0, self.__numRows):
for colCnt in range(0, len(self.__listNum[rowCnt])):
self.__listNum[rowCnt][colCnt] = 100 - self.__listNum[rowCnt][colCnt]
#This function removes every element in listNum that is equal to loc
def removeIf(self, listNum: list, loc: tuple):
location = 0
@@ -317,6 +314,7 @@ class Problem67(Problem):
del listNum[location]
else:
location += 1
#Reset the problem so it can be run again
def reset(self):
super().reset()
@@ -325,6 +323,12 @@ class Problem67(Problem):
self.actualTotal = 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 value of the longest path is {self.actualTotal}"
#Returns the pyramid that was traversed as a string
def getPyramid(self) -> str:
if(not self.solved):
@@ -350,14 +354,6 @@ class Problem67(Problem):
return self.actualTotal
if __name__ == "__main__":
problem = Problem67()
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 value of the longest path is 7273
It took an average of 8.244 seconds to run this problem through 100 iterations