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/Problem31.py
|
||||
#Matthew Ellison
|
||||
# Created: 06-19-20
|
||||
#Modified: 07-19-20
|
||||
#Modified: 10-30-20
|
||||
#How many different ways can £2 be made using any number of coins?
|
||||
#Unless otherwise listed, all of my non-standard imports can be gotten from my pyClasses repository at https://bitbucket.org/Mattrixwv/pyClasses
|
||||
"""
|
||||
@@ -23,7 +23,6 @@
|
||||
|
||||
|
||||
from Problems.Problem import Problem
|
||||
from Stopwatch import Stopwatch
|
||||
from Unsolved import Unsolved
|
||||
|
||||
|
||||
@@ -60,17 +59,21 @@ class Problem31(Problem):
|
||||
#Stop the timer
|
||||
self.timer.stop()
|
||||
|
||||
#Save the results
|
||||
self.result = "There are " + str(self.permutations) + " ways to make 2 pounds with the given denominations of coins"
|
||||
|
||||
#Throw a flag to show the problem is solved
|
||||
self.solved = True
|
||||
|
||||
#Reset the problem so it can be run again
|
||||
def reset(self):
|
||||
super().reset()
|
||||
self.permutations = 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 f"There are {self.permutations} ways to make 2 pounds with the given denominations of coins"
|
||||
#Returns the number of correct permutations of the coins
|
||||
def getPermutations(self) -> int:
|
||||
#If the problem hasn't been solved throw an exception
|
||||
@@ -79,16 +82,6 @@ class Problem31(Problem):
|
||||
return self.permutations
|
||||
|
||||
|
||||
#This calls the appropriate functions if the script is called stand alone
|
||||
if __name__ == "__main__":
|
||||
problem = Problem31()
|
||||
print(problem.getDescription()) #Print the description
|
||||
problem.solve() #Call the function that answers the problem
|
||||
#Print the results
|
||||
print(problem.getResult())
|
||||
print("It took " + problem.getTime() + " to solve this algorithm")
|
||||
|
||||
|
||||
""" Results:
|
||||
There are 73682 ways to make 2 pounds with the given denominations of coins
|
||||
It took an average of 5.519 milliseconds to run this problem through 100 iterations
|
||||
|
||||
Reference in New Issue
Block a user