RosettaCodeData/Task/Count-the-coins/Mathematica/count-the-coins.math
Ingy döt Net d066446780 langs a-z
2013-04-10 22:43:41 -07:00

8 lines
217 B
Text

CountCoins[amount_, coinlist_] := ( ways = ConstantArray[1, amount];
Do[For[j = coin, j <= amount, j++,
If[ j - coin == 0,
ways[[j]] ++,
ways[[j]] += ways[[j - coin]]
]]
, {coin, coinlist}];
ways[[amount]])