mirror of
https://bitbucket.org/Mattrixwv/projecteulerpython.git
synced 2025-12-06 17:43:58 -05:00
Added solution to problem 31
This commit is contained in:
57
Problem31.py
Normal file
57
Problem31.py
Normal file
@@ -0,0 +1,57 @@
|
||||
#ProjectEuler/Python/Problem31.py
|
||||
#Matthew Ellison
|
||||
# Created: 06-19-20
|
||||
#Modified: 06-19-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
|
||||
"""
|
||||
Copyright (C) 2020 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
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
|
||||
from Stopwatch import Stopwatch
|
||||
|
||||
|
||||
#Setup the variables
|
||||
__desiredValue = 200
|
||||
|
||||
def Problem31():
|
||||
permutations = 0
|
||||
#Start with 200p and remove the necessary coins with each loop
|
||||
for pound2 in range(__desiredValue, -1, -200):
|
||||
for pound1 in range(pound2, -1, -100):
|
||||
for pence50 in range(pound1, -1, -50):
|
||||
for pence20 in range(pence50, -1, -20):
|
||||
for pence10 in range(pence20, -1, -10):
|
||||
for pence5 in range(pence10, -1, -5):
|
||||
for pence2 in range(pence5, -1, -2):
|
||||
permutations += 1
|
||||
|
||||
#Print the results
|
||||
print("There are " + str(permutations) + " ways to make 2 pounds with the given denominations of coins")
|
||||
|
||||
#This calls the appropriate functions if the script is called stand alone
|
||||
if __name__ == "__main__":
|
||||
timer = Stopwatch()
|
||||
timer.start()
|
||||
Problem31()
|
||||
timer.stop()
|
||||
print("It took " + timer.getString() + " to run this algorithm")
|
||||
|
||||
""" Results:
|
||||
There are 73682 ways to make 2 pounds with the given denominations of coins
|
||||
It took 2.653 milliseconds to run this algorithm
|
||||
"""
|
||||
Reference in New Issue
Block a user