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/Problem17.py
#Matthew Ellison
# Created: 02-04-19
#Modified: 10-30-20
#Modified: 07-24-21
#If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used?
#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
import math
@@ -34,13 +33,13 @@ class Problem17(Problem):
#Functions
#Constructor
def __init__(self):
def __init__(self) -> None:
super().__init__("If all the numbers from 1 (one) to 1000 (one thousand) inclusive were written out in words, how many letters would be used?")
self.letterCount = 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
@@ -48,6 +47,7 @@ class Problem17(Problem):
#Start the timer
self.timer.start()
#Start with 1 and increment
for num in range(self.__startNum, self.__stopNum + 1):
#Pass the number to a function that will create a string for the number
@@ -55,6 +55,7 @@ class Problem17(Problem):
#Pass the string to a function that will count the number of letters in a string, ignoring whitespace and punctuation and add the amount to the running tally
self.letterCount += self.getNumberChars(currentNumString)
#Stop the timer
self.timer.stop()
@@ -178,22 +179,18 @@ class Problem17(Problem):
return sumOfLetters
#Reset the problem so it can be run again
def reset(self):
def reset(self) -> None:
super().reset()
self.letterCount = 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 all the letters in all the numbers {self.__startNum}-{self.__stopNum} is {self.letterCount}"
#Returns the number of letters asked for
def getLetterCount(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 number of letters")
def getLetterCount(self) -> int:
self.solvedCheck("letter count")
return self.letterCount