Updated to use new library layout

This commit is contained in:
2021-07-24 16:13:05 -04:00
parent d18b3fa9f6
commit 84555edd31
39 changed files with 515 additions and 709 deletions

View File

@@ -1,7 +1,7 @@
#ProjectEuler/Python/Problem18.py
#Matthew Ellison
# Created: 03-12-19
#Modified: 10-30-20
#Modified: 07-24-21
#Find the maximum total from top to bottom
"""
75
@@ -22,7 +22,7 @@
"""
#Unless otherwise listed, all of my non-standard imports can be gotten from my pyClasses repository at https://bitbucket.org/Mattrixwv/pyClasses
"""
Copyright (C) 2020 Matthew Ellison
Copyright (C) 2021 Matthew Ellison
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
@@ -40,7 +40,6 @@
from Problems.Problem import Problem
from Unsolved import Unsolved
from collections import namedtuple
@@ -68,7 +67,7 @@ class Problem18(Problem):
#Functions
#Constructor
def __init__(self):
def __init__(self) -> None:
super().__init__("Find the maximum total from top to bottom")
self.foundPoints = [] #For the points that I have already found the shortest distance to
self.possiblePoints = [] #For the locations you are checking this round
@@ -76,7 +75,7 @@ class Problem18(Problem):
#Operational functions
#Solve the problem
def solve(self):
def solve(self) -> None:
#If the problem has already been solved do nothing and end the function
if(self.solved):
return
@@ -84,6 +83,7 @@ class Problem18(Problem):
#Start the timer
self.timer.start()
#Invert the list so that each element = 100 - element
self.invert()
@@ -124,6 +124,7 @@ class Problem18(Problem):
#Invert the list so it can be read again
self.invert()
#Stop the timer
self.timer.stop()
@@ -131,13 +132,13 @@ class Problem18(Problem):
self.solved = True
#This function turns every number in the array into (100 - num) to allow you to find the largest numbers rather than the smallest
def invert(self):
def invert(self) -> None:
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):
def removeIf(self, listNum: list, loc: tuple) -> None:
location = 0
while(location < len(listNum)):
if((listNum[location].xLocation == loc.xLocation) and (listNum[location].yLocation == loc.yLocation)):
@@ -146,7 +147,7 @@ class Problem18(Problem):
location += 1
#Reset the problem so it can be run again
def reset(self):
def reset(self) -> None:
super().reset()
self.foundPoints.clear()
self.possiblePoints.clear()
@@ -154,33 +155,27 @@ class Problem18(Problem):
#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")
def getResult(self) -> str:
self.solvedCheck("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):
raise Unsolved("You must solve the problem before you can get the pyramid")
results = ""
self.solvedCheck("pyramid of numbers")
pyramidString = ""
#Loop through all elements of the list and print them
for row in self.__listNum:
for column in row:
results += "{:02d}".format(column)
results += '\n'
return results
pyramidString += "{:02d}".format(column)
pyramidString += '\n'
return pyramidString
#Returns the trail the algorithm took as a string
def getTrail(self) -> str:
if(not self.solved):
raise Unsolved("You must solve the problem before you can get the trail")
self.solvedCheck("trail of the shortest path")
#TODO: Implement this
return ""
#Returns the total that was asked for
def getTotal(self) -> int:
if(not self.solved):
raise Unsolved("You must solve the problem before you can get the total")
self.solvedCheck("total")
return self.actualTotal