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/Problem18.py
#Matthew Ellison
# Created: 03-12-19
#Modified: 07-20-20
#Modified: 10-30-20
#Find the maximum total from top to bottom
"""
75
@@ -40,7 +40,6 @@
from Problems.Problem import Problem
from Stopwatch import Stopwatch
from Unsolved import Unsolved
from collections import namedtuple
@@ -128,9 +127,6 @@ class Problem18(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
@@ -139,6 +135,7 @@ class Problem18(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
@@ -147,14 +144,21 @@ class Problem18(Problem):
del listNum[location]
else:
location += 1
#Reset the problem so it can be run again
def reset(self):
super().reset()
self.foundPoints.clear()
self.possiblePoints.clear()
actualTotal = 0
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):
@@ -180,14 +184,6 @@ class Problem18(Problem):
return self.actualTotal
if __name__ == "__main__":
problem = Problem18()
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 value of the longest path is 1074
It took an average of 422.974 microseconds to run this problem through 100 iterations