-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_change copy.py
More file actions
26 lines (21 loc) · 898 Bytes
/
make_change copy.py
File metadata and controls
26 lines (21 loc) · 898 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
def change_possibilities_top_down(amount_left, denominations_left):
# base cases:
# we hit the amount spot on. yes!
if amount_left == 0: return 1
# we overshot the amount left (used too many coins)
if amount_left < 0: return 0
# we're out of denominations
if len(denominations_left) == 0: return 0
print "checking ways to make %i with %s" % (amount_left, denominations_left)
# choose a current_coin
current_coin, rest_of_coins = denominations_left[0], denominations_left[1:]
# see how many possibilities we can get
# for each number of times to use current_coin
num_possibilities = 0
while amount_left >= 0:
num_possibilities += change_possibilities_top_down(amount_left, rest_of_coins)
amount_left -= current_coin
return num_possibilities
amount = 63
denoms = [1,5,10,25]
change_possibilities_top_down(amount,denoms)