-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCS375Lab5.py
37 lines (28 loc) · 1006 Bytes
/
CS375Lab5.py
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
27
28
29
30
31
32
33
34
35
36
37
def coinChange(demoninations, N):
# If N == 0, then it is impossible
if N == 0:
print("Not Possible")
combos = {}
# set i to the last index of demoninations
i = len(demoninations)-1
# Go through all demoninations
while(i >= 0):
# While the demonination is greater than N, keep using the largest demonination until N is no longer bigger than N
while(N >= demoninations[i]):
N -= demoninations[i]
# if demonination has not been previously used, update the dictionary
if demoninations[i] in combos:
combos[demoninations[i]] += 1
# update the current number of demoninations if it was found before
else:
combos[demoninations[i]] = 1
i -= 1
# Check if demoninations can sum up to N
if N != 0:
print("Not Possible")
else:
print(combos)
print(len(combos))
def main():
coinChange((1, 5, 10, 25, 100), 137)
main()