Count the coins: Difference between revisions

Added Algol 68 version
(Added another solution)
(Added Algol 68 version)
Line 56:
Output:<pre> 242
13398445413854501</pre>
 
=={{header|ALGOL 68}}==
{{works with|ALGOL 68G|Any - tested with release 2.4.1}}
{{trans|Haskell}}
This corresponds to a "naive" Haskell version; to do the larger problem will require a better approach.
 
<lang Algol68>
#
Rosetta Code "Count the coins"
This is a direct translation of a Haskell version, using an array rather than
a list. LWB, UPB, and array slicing makes the mapping very simple:
LWB > UPB <=> []
LWB = UPB <=> [x]
a[LWB a} <=> head xs
a[LWB a + 1:] <=> tail xs
#
 
BEGIN
PROC ways to make change = ([] INT denoms, INT amount) INT :
BEGIN
IF amount = 0 THEN
1
ELIF LWB denoms > UPB denoms THEN
0
ELIF LWB denoms = UPB denoms THEN
(amount MOD denoms[LWB denoms] = 0 | 1 | 0)
ELSE
INT sum := 0;
FOR i FROM 0 BY denoms[LWB denom] TO amount DO
sum +:= ways to make change(denoms[LWB denoms + 1:], amount - i)
OD;
sum
FI
END;
[] INT denoms = (25, 10, 5, 1);
print((ways to make change(denoms, 100), newline))
END
</lang>
Output:<pre>
+242
</pre>
 
=={{header|AutoHotkey}}==