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 @@
#Project Euler/Python/Problem10.py
#Matthew Ellison
# Created: 01-30-19
#Modified: 10-30-20
#Modified: 07-24-21
#Find the sum of all the primes below two million
#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 getPrimes
import NumberAlgorithms
class Problem10(Problem):
@@ -33,13 +32,13 @@ class Problem10(Problem):
#Functions
#Constructor
def __init__(self):
def __init__(self) -> None:
super().__init__("Find the sum of all the primes below two million")
self.sum = 0 #The sum of all of the prime numbers
#Operational functions
#Solve the function
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,11 +46,13 @@ class Problem10(Problem):
#Start the timer
self.timer.start()
#Get all of the primes < 2000000
primes = getPrimes(self.__numberGreaterThanPrimes)
primes = NumberAlgorithms.getPrimes(self.__numberGreaterThanPrimes)
#Get the sum of the list
self.sum = sum(primes)
#Stop the timer
self.timer.stop()
@@ -59,22 +60,18 @@ class Problem10(Problem):
self.solved = True
#Reset the problem so it can be run again
def reset(self):
def reset(self) -> None:
super().reset()
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"The sum of all the prime numbers less than {self.__numberGreaterThanPrimes + 1} is {self.sum}"
#Returns the sum that was requested
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")
return self.sum