Striverмда…это я провтыкал :(.
но к сожалению не обрабатывает некоторые ситуаци
Но вроде поправил :)
def GetMoney(m, nom_list):
def get(m, nom_list):
res = {}
for nom in nom_list:
num = m / nom
res = num
m = m - nom * num
return res, m
m = int(m)
if m < 0:
print “m - Incorrect value”
return
nom_list =
nom_list.sort(reverse=True)
res, m = get(m, nom_list)
while m:
n = -2
while 1:
try:
if res[nom_list]:
break
n -= 1
except IndexError:
print “Can not find solution”
return
res[nom_list] -= 1
m += sum([i*res for i in nom_list], nom_list)
tmp, m = get(m, nom_list)
res.update(tmp)
return res
for i in xrange(1, 25):
res = GetMoney(i, (3, 5, 10))
if res:
print i, ‘-’, res
Результат
Can not find solution
Can not find solution
3 - {10: 0, 3: 1, 5: 0}
Can not find solution
5 - {10: 0, 3: 0, 5: 1}
6 - {10: 0, 3: 2, 5: 0}
Can not find solution
8 - {10: 0, 3: 1, 5: 1}
9 - {10: 0, 3: 3, 5: 0}
10 - {10: 1, 3: 0, 5: 0}
11 - {10: 0, 3: 2, 5: 1}
12 - {10: 0, 3: 4, 5: 0}
13 - {10: 1, 3: 1, 5: 0}
14 - {10: 0, 3: 3, 5: 1}
15 - {10: 1, 3: 0, 5: 1}
16 - {10: 1, 3: 2, 5: 0}
17 - {10: 0, 3: 4, 5: 1}
18 - {10: 1, 3: 1, 5: 1}
19 - {10: 1, 3: 3, 5: 0}
20 - {10: 2, 3: 0, 5: 0}
21 - {10: 1, 3: 2, 5: 1}
22 - {10: 1, 3: 4, 5: 0}
23 - {10: 2, 3: 1, 5: 0}
24 - {10: 1, 3: 3, 5: 1}