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 @@
|
||||
#Project Eulter/Python/Problem7.py
|
||||
#Matthew Ellison
|
||||
# Created: 01-29-19
|
||||
#Modified: 10-30-20
|
||||
#Modified: 07-24-21
|
||||
#What is the 10001st prime number?
|
||||
#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 Unsolved import Unsolved
|
||||
from Algorithms import getNumPrimes
|
||||
import NumberAlgorithms
|
||||
|
||||
|
||||
class Problem7(Problem):
|
||||
@@ -33,13 +32,13 @@ class Problem7(Problem):
|
||||
|
||||
#Functions
|
||||
#Constructor
|
||||
def __init__(self):
|
||||
def __init__(self) -> None:
|
||||
super().__init__("What is the 10001st prime number?")
|
||||
self.primes = []
|
||||
|
||||
#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,8 +46,10 @@ class Problem7(Problem):
|
||||
#Start the timer
|
||||
self.timer.start()
|
||||
|
||||
|
||||
#Get the correct number of primes
|
||||
self.primes = getNumPrimes(self.__numPrimes)
|
||||
self.primes = NumberAlgorithms.getNumPrimes(self.__numPrimes)
|
||||
|
||||
|
||||
#Stop the timer
|
||||
self.timer.stop()
|
||||
@@ -57,22 +58,18 @@ class Problem7(Problem):
|
||||
self.solved = True
|
||||
|
||||
#Reset the problem so it can be run again
|
||||
def reset(self):
|
||||
def reset(self) -> None:
|
||||
super().reset()
|
||||
self.primes.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 {self.__numPrimes}st prime number is {self.primes[self.__numPrimes - 1]}"
|
||||
#Returns the requested prime number
|
||||
def getPrime(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 requested prime")
|
||||
self.solvedCheck("prime")
|
||||
return self.primes[len(self.primes) - 1]
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user