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/Problem11.py
#Matthew Ellison
# Created: 01-31-19
#Modified: 10-30-20
#Modified: 07-24-21
#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
@@ -27,7 +27,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
@@ -45,8 +45,7 @@
from Problems.Problem import Problem
from Unsolved import Unsolved
from Algorithms import prod
from ArrayAlgorithms import prod
class Problem11(Problem):
@@ -74,13 +73,13 @@ class Problem11(Problem):
#Functions
#Constructor
def __init__(self):
def __init__(self) -> None:
super().__init__("What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the 20×20 grid?")
self.greatestProduct = []
#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
@@ -92,6 +91,7 @@ class Problem11(Problem):
#Start the timer
self.timer.start()
#Loop through every location in the grid
for row in range(0, len(self.__grid)):
for col in range (0, len(self.__grid[row])):
@@ -149,6 +149,7 @@ class Problem11(Problem):
if(prod(currentNumbers) > prod(self.greatestProduct)):
self.greatestProduct = currentNumbers.copy()
#Stop the timer
self.timer.stop()
@@ -156,28 +157,22 @@ class Problem11(Problem):
self.solved = True
#Reset the problem so it can be run again
def reset(self):
def reset(self) -> None:
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")
def getResult(self) -> str:
self.solvedCheck("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
if(not self.solved):
raise Unsolved("You must solve the problem before you can get the numbers being searched")
self.solvedCheck("numbers")
return self.greatestProduct
#Returns the product that was requested
def getProduct(self) -> int:
#If the problem hasn't been solved throw an exception
if(not self.solved):
raise Unsolved("You must solve the problem before you can get the product")
self.solvedCheck("product of the numbers")
return prod(self.greatestProduct)