Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''In England the currency is made up of pound, £, and pence, p, and there are eight coins in general circulation:
- 1p, 2p, 5p, 10p, 20p, 50p, £1 (100p) and £2 (200p).
- It is possible to make £2 in the following way:
- 1×£1 + 1×50p + 2×20p + 1×5p + 1×2p + 3×1p
- How many different ways can £2 be made using any number of coins?'''
- def coinCombi(n):
- import copy
- coins = {'1': 0, '2': 0, '5': 0, '10': 0, '20': 0, '50': 0, '100': 0, '200': 0}
- solution = []
- for value in range(1, n + 1, 1):
- valueSolve = []
- for coin in coins:
- if int(coin) < value:
- diff = value - int(coin)
- newSolve = copy.deepcopy(solution[diff - 1])
- for solve in newSolve:
- solve[coin] = solve[coin] + 1
- for x in newSolve:
- if x not in valueSolve:
- valueSolve.append(x)
- elif value - int(coin) == 0:
- currentSolve = copy.deepcopy(coins)
- currentSolve[coin] = currentSolve[coin] + 1
- valueSolve.append(currentSolve)
- solution.append(valueSolve)
- return len(solution[-1])
- coinCombi(200)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement