Count the coins: Difference between revisions
m
→{{header|Perl 6}}: one code block
SqrtNegInf (talk | contribs) m (→{{header|Perl 6}}: one code block) |
|||
Line 1,937:
{{works with|rakudo|2015.09}}
{{trans|Ruby}}
<lang perl6>
sub change-r($amount, @coins) {
my @cache = $[1 xx @coins];
Line 1,946 ⟶ 1,947:
multi ways($,@) { 0 }
# more efficient to start with coins sorted in descending order
ways($amount, @coins.sort(-*).list);
}
{{out}}▼
<pre>242▼
13398445413854501</pre>▼
▲===Iterative===
▲<lang perl6>sub ways-to-make-change-slowly(\n, @coins) {
my @table = [1 xx @coins], [0 xx @coins] xx n;
for 1..n X ^@coins -> (\i, \j) {
Line 1,966:
}
say
say
Both versions produce the same output.
▲{{out}}
▲<pre>242
▲13398445413854501</pre>
=={{header|Phix}}==
|