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/Problem3.py
#Matthew Ellison
# Created: 01-27-19
#Modified: 10-30-20
#Modified: 07-24-21
#The largest prime factor of 600851475143
#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,8 +23,7 @@
from Problems.Problem import Problem
from Algorithms import getFactors
from Unsolved import Unsolved
import NumberAlgorithms
class Problem3(Problem):
@@ -33,13 +32,13 @@ class Problem3(Problem):
#Functions
#Constructor
def __init__(self):
def __init__(self) -> None:
super().__init__("What is the largest prime factor of 600851475143?")
self.factors = []
#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,10 +46,12 @@ class Problem3(Problem):
#Start the timer
self.timer.start()
#Get the factors of the number
self.factors = getFactors(self.__goalNumber)
self.factors = NumberAlgorithms.getFactors(self.__goalNumber)
#The last element should be the largest factor
#Stop the timer
self.timer.stop()
@@ -58,32 +59,23 @@ class Problem3(Problem):
self.solved = True
#Reset the problem so it can be run again
def reset(self):
def reset(self) -> None:
super().reset()
self.factors.clear()
#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 largest prime factor of {self.__goalNumber} is {self.factors[(len(self.factors) - 1)]}"
#Returns the list of factors of the number
def getFactors(self) -> list:
#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 factors")
self.solvedCheck("factors")
return self.factors
#Returns the largest factor of the number
def getLargestFactor(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 largest factor")
self.solvedCheck("largest factor")
return self.factors[(len(self.factors) - 1)]
#Returns the number for which we are getting the factor
def getGoalNumber(self) -> int:
return self.__goalNumber
"""Results: