Jump to content

Count the coins: Difference between revisions

(Added more efficient version, also inspired by a Haskell version)
Line 215:
INT denom = denoms[i];
FOR j FROM 0 TO amount DO new counts[j] := 0 OD;
FOR kj FROM 0 TO amount DO
IF LONG INT count = counts[kj]; count > 0 THEN
FOR lk FROM kj + denom BY denom TO amount DO
new counts[lk] +:= count
OD
FI;
OD; counts[j] +:= new counts[j]
OD
FOR j FROM 0 TO amount DO counts[j] +:= new counts[j] OD
OD;
counts[amount]
Cookies help us deliver our services. By using our services, you agree to our use of cookies.