aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author冯昶 <seaker@qq.com>2020-08-26 18:35:06 +0800
committer冯昶 <seaker@qq.com>2020-08-26 18:35:06 +0800
commit2ff7886e24f0ee207d3aa299d2a34cf63e8f8378 (patch)
tree524e81ae34c8b3a48c61d518d82bb561bc804661
parentec9e40b0acf8571ff15678cddd4f19eded756e72 (diff)
downloadperlweeklychallenge-club-2ff7886e24f0ee207d3aa299d2a34cf63e8f8378.tar.gz
perlweeklychallenge-club-2ff7886e24f0ee207d3aa299d2a34cf63e8f8378.tar.bz2
perlweeklychallenge-club-2ff7886e24f0ee207d3aa299d2a34cf63e8f8378.zip
#075 ch-1.raku
-rwxr-xr-xchallenge-075/feng-chang/raku/ch-1.raku19
1 files changed, 19 insertions, 0 deletions
diff --git a/challenge-075/feng-chang/raku/ch-1.raku b/challenge-075/feng-chang/raku/ch-1.raku
new file mode 100755
index 0000000000..2cfd88dfb6
--- /dev/null
+++ b/challenge-075/feng-chang/raku/ch-1.raku
@@ -0,0 +1,19 @@
+#!/bin/env raku
+
+sub coins-sum(Int:D @C, Int:D $S, Int:D @solution) {
+ { say @solution; return; } if $S == 0;
+ return if $S < @C[0];
+
+ my Int @coins = @C;
+ while @coins.elems > 0 {
+ my Int @Sol = @solution;
+ @Sol.push(@coins[0]);
+ coins-sum(@coins, $S - @coins[0], @Sol);
+
+ @coins.shift;
+ }
+}
+
+my Int @coins = 1, 2, 4;
+my Int @solution;
+coins-sum(@coins, 6, @solution);