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,11 +1,11 @@
#ProjectEuler/Python/Problem28.py
#Matthew Ellison
# Created: 09-22-19
#Modified: 10-30-20
#Modified: 07-24-21
#What is the sum of the numbers on the diagonals in a 1001 by 1001 spiral formed by starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral
#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
@@ -23,7 +23,6 @@
from Problems.Problem import Problem
from Unsolved import Unsolved
class Problem28(Problem):
@@ -31,13 +30,13 @@ class Problem28(Problem):
grid = []
#Functions
#Constructor
def __init__(self):
def __init__(self) -> None:
super().__init__("What is the sum of the numbers on the diagonals in a 1001 by 1001 spiral formed by starting with the number 1 and moving to the right in a clockwise direction?")
self.sumOfDiagonals = 0
#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
@@ -45,11 +44,13 @@ class Problem28(Problem):
#Start the timer
self.timer.start()
#Setup the grid
self.grid = self.setupGrid()
#Find the sum of the diagonals in the grid
self.sumOfDiagonals = self.findSum()
#Stop the timer
self.timer.stop()
@@ -120,25 +121,21 @@ class Problem28(Problem):
return sumOfDiagonals
#Reset the problem so it can be run again
def reset(self):
def reset(self) -> None:
super().reset()
self.sumOfDiagonals = 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")
def getResult(self) -> str:
self.solvedCheck("result")
return f"The sum of the diagonals in the given grid is {self.sumOfDiagonals}"
#Returns the grid
def getGrid(self) -> list:
return self.grid
#Returns the sum of the diagonals
def getSum(self) -> int:
#If the problem hasn't been solved throw an exception
if(not self.solved):
raise Unsolved("You must solve the problem before can you see the sum")
self.solvedCheck("sum")
return self.sumOfDiagonals