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,10 +1,10 @@
|
||||
#ProjectEuler/ProjectEulerPython/Problems/Problem.py
|
||||
#Matthew Ellison
|
||||
# Created: 07-11-20
|
||||
#Modified: 07-11-20
|
||||
#Modified: 07-23-21
|
||||
#This is a base class for problems to use as a template
|
||||
"""
|
||||
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
|
||||
@@ -28,9 +28,13 @@ from Unsolved import Unsolved
|
||||
|
||||
class Problem(metaclass=abc.ABCMeta):
|
||||
#Functions
|
||||
#Make sure the problem has been solved and throw an exception if not
|
||||
def solvedCheck(self, str: str) -> None:
|
||||
if(not self.solved):
|
||||
raise Unsolved("You must solve the problem before you can see the " + str)
|
||||
#Constructor
|
||||
@abc.abstractmethod
|
||||
def __init__(self, description: str):
|
||||
def __init__(self, description: str) -> None:
|
||||
#Instance variables
|
||||
self.timer = Stopwatch()
|
||||
self.description = description
|
||||
@@ -39,27 +43,24 @@ class Problem(metaclass=abc.ABCMeta):
|
||||
#Returns the description of the problem
|
||||
def getDescription(self) -> str:
|
||||
return self.description
|
||||
#Returns the time taken to run the problem as a string
|
||||
def getTime(self) -> str:
|
||||
self.solvedCheck("time it took to run the algorithm")
|
||||
return self.timer.getString()
|
||||
#Returns the timer as a stopwatch
|
||||
def getTimer(self) -> Stopwatch:
|
||||
self.solvedCheck("timer")
|
||||
return self.timer
|
||||
#Reset the problem so it can be run again
|
||||
def reset(self) -> None:
|
||||
self.timer.reset()
|
||||
self.solved = False
|
||||
self.result = ""
|
||||
#Solve the problem
|
||||
@abc.abstractmethod
|
||||
def solve(self) -> None:
|
||||
pass
|
||||
#Returns the result of solving the problem
|
||||
@abc.abstractmethod
|
||||
def getResult(self) -> str:
|
||||
pass
|
||||
#Returns the time taken to run the problem as a string
|
||||
def getTime(self) -> str:
|
||||
#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 time")
|
||||
return self.timer.getString()
|
||||
#Returns the timer as a stopwatch
|
||||
def getTimer(self) -> Stopwatch:
|
||||
#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 timer")
|
||||
return self.timer
|
||||
#Solve the problem
|
||||
@abc.abstractmethod
|
||||
def solve(self):
|
||||
pass
|
||||
def reset(self):
|
||||
self.timer.reset()
|
||||
self.solved = False
|
||||
self.result = ""
|
||||
|
||||
Reference in New Issue
Block a user