mirror of
https://bitbucket.org/Mattrixwv/projecteulerpython.git
synced 2025-12-06 17:43:58 -05:00
Updated to use new library layout
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#ProjectEuler/Python/Problem67.py
|
||||
#Matthew Ellison
|
||||
# Created: 03-26-19
|
||||
#Modified: 10-30-20
|
||||
#Modified: 07-24-21
|
||||
#Find the maximum total from top to bottom
|
||||
"""
|
||||
59
|
||||
@@ -107,7 +107,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
|
||||
@@ -125,7 +125,6 @@
|
||||
|
||||
|
||||
from Problems.Problem import Problem
|
||||
from Unsolved import Unsolved
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
@@ -238,7 +237,7 @@ class Problem67(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
|
||||
@@ -246,7 +245,7 @@ class Problem67(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
|
||||
@@ -254,6 +253,7 @@ class Problem67(Problem):
|
||||
#Start the timer
|
||||
self.timer.start()
|
||||
|
||||
|
||||
#Invert the list so that each element = 100 - element
|
||||
self.invert()
|
||||
|
||||
@@ -294,6 +294,7 @@ class Problem67(Problem):
|
||||
#Invert the list so it can be read again
|
||||
self.invert()
|
||||
|
||||
|
||||
#Stop the timer
|
||||
self.timer.stop()
|
||||
|
||||
@@ -301,13 +302,13 @@ class Problem67(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)):
|
||||
@@ -316,7 +317,7 @@ class Problem67(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()
|
||||
@@ -324,33 +325,27 @@ class Problem67(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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user