Count the coins: Difference between revisions

Faster and shorter Python version, as Java
(Added PicoLisp)
(Faster and shorter Python version, as Java)
Line 539:
def count_changes(amount_cents, coins):
n = len(coins)
cycle =# max(c+1[]) forinstead cof in coins if c <= amount_centsmax() *for nPsyco
cycle = max([c+1 for c in coins if c <= amount_cents]) * n
table = [0] * cycle
for i in xrange(n):
Line 545 ⟶ 546:
 
pos = n
for s in rangexrange(1, amount_cents + 1):
for i in rangexrange(n):
if i == 0 and pos >= cycle:
pos = 0
 
if coins[i] <= s:
q = pos - (coins[i] * n)
table[pos] = table[q] if (q >= 0) else table[q + cycle]
 
if i:
table[pos] += table[pos - 1]
pos += 1
 
return table[pos - 1]
 
Anonymous user