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/Problem2.py
#Matthew Ellison
# Created: 01-26-19
#Modified: 10-30-20
#Modified: 07-23-21
#The sum of the even Fibonacci numbers less than 4,000,000
#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 getAllFib
from Unsolved import Unsolved
import NumberAlgorithms
class Problem2(Problem):
@@ -33,13 +32,13 @@ class Problem2(Problem):
#Functions
#Constructor
def __init__(self):
def __init__(self) -> None:
super().__init__("What is the sum of the even Fibonacci numbers less than 4,000,000?")
self.fullSum = 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,14 +46,16 @@ class Problem2(Problem):
#Start the timer
self.timer.start()
#Get a list of all fibonacci numbers < 4,000,000
fibNums = getAllFib(self.__topNumber) #Send it - 1 because it is < __topNumber
fibNums = NumberAlgorithms.getAllFib(self.__topNumber)
#Step through every element in the list checking if it is even
for num in fibNums:
#If the number is even add it to the running tally
if((num % 2) == 0):
self.fullSum += num
#Stop the timer
self.timer.stop()
@@ -62,22 +63,18 @@ class Problem2(Problem):
self.solved = True
#Reset the problem
def reset(self):
def reset(self) -> None:
super().reset()
self.fullSum = 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 even Fibonacci numbers less than {self.__topNumber + 1} is {self.fullSum}"
#Returns the requested sum
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 can you see the sum")
self.solvedCheck("sum")
return self.fullSum