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 @@
|
||||
#ProjectEuler/Python/Problem31.py
|
||||
#Matthew Ellison
|
||||
# Created: 06-19-20
|
||||
#Modified: 10-30-20
|
||||
#Modified: 07-24-21
|
||||
#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
|
||||
"""
|
||||
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,7 +23,6 @@
|
||||
|
||||
|
||||
from Problems.Problem import Problem
|
||||
from Unsolved import Unsolved
|
||||
|
||||
|
||||
class Problem31(Problem):
|
||||
@@ -32,13 +31,13 @@ class Problem31(Problem):
|
||||
|
||||
#Functions
|
||||
#Constructor
|
||||
def __init__(self):
|
||||
def __init__(self) -> None:
|
||||
super().__init__("How many different ways can 2 pounds be made using any number of coins?")
|
||||
self.permutations = 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
|
||||
@@ -46,6 +45,7 @@ class Problem31(Problem):
|
||||
#Start the timer
|
||||
self.timer.start()
|
||||
|
||||
|
||||
#Start with 200p and remove the necessary coins with each loop
|
||||
for pound2 in range(self.__desiredValue, -1, -200):
|
||||
for pound1 in range(pound2, -1, -100):
|
||||
@@ -56,6 +56,7 @@ class Problem31(Problem):
|
||||
for pence2 in range(pence5, -1, -2):
|
||||
self.permutations += 1
|
||||
|
||||
|
||||
#Stop the timer
|
||||
self.timer.stop()
|
||||
|
||||
@@ -63,22 +64,18 @@ class Problem31(Problem):
|
||||
self.solved = True
|
||||
|
||||
#Reset the problem so it can be run again
|
||||
def reset(self):
|
||||
def reset(self) -> None:
|
||||
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")
|
||||
def getResult(self) -> str:
|
||||
self.solvedCheck("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
|
||||
if(not self.solved):
|
||||
raise Unsolved("You must solve the problem before can you see the number of permutations")
|
||||
self.solvedCheck("number of correct permutations of the coins")
|
||||
return self.permutations
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user