mirror of
https://bitbucket.org/Mattrixwv/projecteulerpython.git
synced 2025-12-06 17:43:58 -05:00
Updated all problems to use fstrings and results()
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#ProjectEuler/Python/Problem2.py
|
||||
#Matthew Ellison
|
||||
# Created: 01-26-19
|
||||
#Modified: 10-29-20
|
||||
#Modified: 10-30-20
|
||||
#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
|
||||
"""
|
||||
@@ -65,13 +65,14 @@ class Problem2(Problem):
|
||||
def reset(self):
|
||||
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")
|
||||
return "The sum of all even Fibonacci numbers less than " + str(self.__topNumber + 1) + " is " + str(self.fullSum)
|
||||
#Gets
|
||||
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
|
||||
@@ -80,15 +81,6 @@ class Problem2(Problem):
|
||||
return self.fullSum
|
||||
|
||||
|
||||
#If you are running this file, automatically start the correct function
|
||||
if __name__ == '__main__':
|
||||
problem = Problem2() #Call the function that answers the question
|
||||
print(problem.getDescription()) #Print the description of the problem
|
||||
problem.solve() #Solve the problem
|
||||
#Print the results
|
||||
print(problem.getResult())
|
||||
print("It took " + problem.getTime() + " to solve this algorithm")
|
||||
|
||||
"""Results:
|
||||
The sum of all even Fibonacci numbers less than 4000000 is 4613732
|
||||
It took an average of 10.286 microseconds to run this problem through 100 iterations
|
||||
|
||||
Reference in New Issue
Block a user