-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbill-breaker.py
More file actions
46 lines (35 loc) · 1.03 KB
/
bill-breaker.py
File metadata and controls
46 lines (35 loc) · 1.03 KB
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
38
39
40
41
42
43
44
45
46
def static(amount, coins):
result = []
i = 0
while amount > 0:
coin = coins[i]
if amount < coin:
if coin == coins[-1]:
result.append(-1)
return result
i += 1
else:
amount -= coin
result.append(coin)
return result
def recursive(amount, coins):
if len(coins):
coin = coins[0]
elif amount > 0:
return [-1]
else:
return []
if amount < coin:
return recursive(amount, coins[1:])
result = []
n = amount // coin
amount -= (n * coin)
result.extend([coin]*n)
result.extend(recursive(amount, coins[1:]))
return result
if __name__ == "__main__":
money = int(input('How much money do you want to convert? '))
coins = [100_000, 50_000, 10_000, 5_000, 2_000, 1_000, 500]
print(f'Static: {static(money, coins)}')
print(f'Recursive: {recursive(money, coins)}')
input('\nPress enter to exit...')