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,9 +23,7 @@
|
||||
|
||||
|
||||
from Problems.Problem import Problem
|
||||
from Unsolved import Unsolved
|
||||
|
||||
import Algorithms
|
||||
import NumberAlgorithms
|
||||
|
||||
|
||||
class Problem35(Problem):
|
||||
@@ -34,7 +32,7 @@ class Problem35(Problem):
|
||||
|
||||
#Functions
|
||||
#Constructor
|
||||
def __init__(self):
|
||||
def __init__(self) -> None:
|
||||
super().__init__("Find the sum of all numbers which are equal to the sum of the factorial of their digits")
|
||||
self.primes = []
|
||||
self.circularPrimes = []
|
||||
@@ -50,7 +48,7 @@ class Problem35(Problem):
|
||||
|
||||
#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
|
||||
@@ -58,8 +56,9 @@ class Problem35(Problem):
|
||||
#Start the timer
|
||||
self.timer.start()
|
||||
|
||||
|
||||
#Get all primes under 1,000,000
|
||||
self.primes = Algorithms.getPrimes(self.__max_num)
|
||||
self.primes = NumberAlgorithms.getPrimes(self.__max_num)
|
||||
#Go through all primes, get all their rotations, and check if those numbers are also primes
|
||||
for prime in self.primes:
|
||||
allRotationsPrime = True
|
||||
@@ -74,6 +73,7 @@ class Problem35(Problem):
|
||||
if(allRotationsPrime):
|
||||
self.circularPrimes.append(prime)
|
||||
|
||||
|
||||
#Stop the timer
|
||||
self.timer.stop()
|
||||
|
||||
@@ -81,7 +81,7 @@ class Problem35(Problem):
|
||||
self.solved = True
|
||||
|
||||
#Reset the problem so it can be run again
|
||||
def reset(self):
|
||||
def reset(self) -> None:
|
||||
super().reset()
|
||||
self.primes = []
|
||||
self.circularPrimes = []
|
||||
@@ -89,27 +89,19 @@ class Problem35(Problem):
|
||||
#Gets
|
||||
#Returns a string with the solution to the problem
|
||||
def getResult(self) -> str:
|
||||
#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")
|
||||
self.solvedCheck("result")
|
||||
return f"The number of all circular prime numbers under {self.__max_num} is {len(self.circularPrimes)}"
|
||||
#Returns the list of primes < max_num
|
||||
def getPrimes(self) -> list:
|
||||
#If the problem hasn't been solved throw an exception
|
||||
if(not self.solved):
|
||||
raise Unsolved("You must solve the porblem before you can see the primes")
|
||||
self.solvedCheck("list of primes")
|
||||
return self.primes
|
||||
#Returns the list of circular primes < max_num
|
||||
def getCircularPrimes(self) -> list:
|
||||
#If the problem hasn't been solved throw an exception
|
||||
if(not self.solved):
|
||||
raise Unsolved("You must solve the porblem before you can see the circular primes")
|
||||
self.solvedCheck("list of circular primes")
|
||||
return self.circularPrimes
|
||||
#Returns the number of circular primes
|
||||
def getNumCircularPrimes(self) -> list:
|
||||
#If the problem hasn't been solved throw an exception
|
||||
if(not self.solved):
|
||||
raise Unsolved("You must solve the porblem before you can see the number of circular primes")
|
||||
self.solvedCheck("number of circular primes")
|
||||
return len(self.circularPrimes)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user