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:
@@ -23,7 +23,6 @@
|
||||
|
||||
|
||||
from Problems.Problem import Problem
|
||||
from Unsolved import Unsolved
|
||||
|
||||
|
||||
class Problem20(Problem):
|
||||
@@ -32,14 +31,14 @@ class Problem20(Problem):
|
||||
|
||||
#Functions
|
||||
#Constructor
|
||||
def __init__(self):
|
||||
def __init__(self) -> None:
|
||||
super().__init__("What is the sum of the digits of 100!?")
|
||||
self.num = 1 #Holds the number 100!
|
||||
self.sum = 0 #The sum of the digts of num
|
||||
|
||||
#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
|
||||
@@ -47,6 +46,7 @@ class Problem20(Problem):
|
||||
#Start the timer
|
||||
self.timer.start()
|
||||
|
||||
|
||||
#Run through every number from 1 to 100 and multiply it by the current num to get 100!
|
||||
for cnt in range(1, self.__top_num + 1):
|
||||
self.num *= cnt
|
||||
@@ -57,35 +57,30 @@ class Problem20(Problem):
|
||||
for char in numString:
|
||||
self.sum += int(char)
|
||||
|
||||
|
||||
#Stop the timer
|
||||
self.timer.stop()
|
||||
|
||||
#Throw a flag to show the problem is solved
|
||||
self.solved = True
|
||||
#Reset the problem so it can be run again
|
||||
def reset(self):
|
||||
def reset(self) -> None:
|
||||
super().reset()
|
||||
self.num = 1
|
||||
self.sum = 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"100! = {self.num}\nThe sum of the digits is: {self.sum}"
|
||||
#Returns the number 100!
|
||||
def getNumber(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 number")
|
||||
self.solvedCheck("number")
|
||||
return self.num
|
||||
#Returns the sum of the digits of 100!
|
||||
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 you can get the sum")
|
||||
self.solvedCheck("sum of the digits")
|
||||
return self.sum
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user