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,11 +1,11 @@
|
||||
#ProjectEulter/Python/Project5.py
|
||||
#Matthew Ellison
|
||||
# Created: 01-28-19
|
||||
#Modified: 10-30-20
|
||||
#Modified: 07-24-21
|
||||
#What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
|
||||
#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: it 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 Problem5(Problem):
|
||||
@@ -33,13 +32,13 @@ class Problem5(Problem):
|
||||
|
||||
#Functions
|
||||
#Constructor
|
||||
def __init__(self):
|
||||
def __init__(self) -> None:
|
||||
super().__init__("What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?")
|
||||
self.smallestNum = 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
|
||||
@@ -47,6 +46,7 @@ class Problem5(Problem):
|
||||
#Start the timer
|
||||
self.timer.start()
|
||||
|
||||
|
||||
#Start at 20 and loop through all numbers until it find one that works
|
||||
#It must be at least 20 to be divisible by 20
|
||||
numFound = False #A flag for finding the divisible number
|
||||
@@ -68,6 +68,7 @@ class Problem5(Problem):
|
||||
#Set the smallest number to the number we just found
|
||||
self.smallestNum = currentNum
|
||||
|
||||
|
||||
#Stop the timer
|
||||
self.timer.stop()
|
||||
|
||||
@@ -75,22 +76,18 @@ class Problem5(Problem):
|
||||
self.solved = True
|
||||
|
||||
#Reset the problem so it can be run again
|
||||
def reset(self):
|
||||
def reset(self) -> None:
|
||||
super().reset()
|
||||
self.smallestNum = 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 smallest positive number that is evenly divisible by all numbers 1-20 is {self.smallestNum}"
|
||||
#Returns the requested number
|
||||
def getNumber(self) -> int:
|
||||
#If the problem hasn't been solved throw an exceptions
|
||||
if(not self.solved):
|
||||
raise Unsolved("You must solve the problem before you can get the requested number")
|
||||
self.solvedCheck("number")
|
||||
return self.smallestNum
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user