Renamed all folders

This commit is contained in:
2021-04-16 16:58:48 +02:00
parent dbc6cfef05
commit 197b3eea8a
62 changed files with 0 additions and 0 deletions

32
031/main.py Normal file
View File

@@ -0,0 +1,32 @@
# Coin sums
# You have coins for 1p, 2p, 5p, 10p, 20p, 50p, 100p and 200p
# Find out how many ways there are to pay 200p
def count(S, n, N):
if N == 0:
return 1
if N < 0 or n < 0:
return 0
# Case 1. include current coin S[n] in solution and recur
# with remaining change (N - S[n]) with same number of coins
incl = count(S, n, N - S[n])
# Case 2. exclude current coin S[n] from solution and recur
# for remaining coins (n - 1)
excl = count(S, n - 1, N)
# return total ways by including or excluding current coin
return incl + excl
if __name__ == '__main__':
S = [1, 2, 5, 10, 20, 50, 100, 200]
N = 200
print("Total number of ways to get desired change is", count(S, len(S) - 1, N))