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/Problem19.py
#Matthew Ellison
# Created: 03-13-19
#Modified: 10-30-20
#Modified: 07-24-21
#How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?
"""
You are given the following information, but you may prefer to do some research for yourself.
@@ -16,7 +16,7 @@ A leap year occurs on any year evenly divisible by 4, but not on a century unles
"""
#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
@@ -34,7 +34,6 @@ A leap year occurs on any year evenly divisible by 4, but not on a century unles
from Problems.Problem import Problem
from Unsolved import Unsolved
class DAYS:
@@ -55,13 +54,13 @@ class Problem19(Problem):
#Functions
#Constructor
def __init__(self):
def __init__(self) -> None:
super().__init__("How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?")
self.totalSundays = 0 #Keep track of the number of sundays
#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
@@ -69,6 +68,7 @@ class Problem19(Problem):
#Start the timer
self.timer.start()
#Run for all years from start to end
for year in range(self.__startYear, self.__endYear + 1):
#Run for all months in the year
@@ -80,6 +80,7 @@ class Problem19(Problem):
elif(day == DAYS.SUNDAY):
self.totalSundays += 1
#Stop the timer
self.timer.stop()
@@ -168,22 +169,18 @@ class Problem19(Problem):
return False
#Reset the problem so it can be run again
def reset(self):
def reset(self) -> None:
super().reset()
self.totalSundays = 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"There are {self.totalSundays} Sundays that landed on the first of the month from {self.__startYear} to {self.__endYear}"
#Returns the total sundays that were asked for
def getTotalSundays(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 get the total sundays")
def getTotalSundays(self) -> int:
self.solvedCheck("total number of sundays")
return self.totalSundays