aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-252/feng-chang/raku/ch-1.raku5
-rwxr-xr-xchallenge-252/feng-chang/raku/ch-2.raku9
-rwxr-xr-xchallenge-252/feng-chang/raku/test.raku32
3 files changed, 46 insertions, 0 deletions
diff --git a/challenge-252/feng-chang/raku/ch-1.raku b/challenge-252/feng-chang/raku/ch-1.raku
new file mode 100755
index 0000000000..39ced4a162
--- /dev/null
+++ b/challenge-252/feng-chang/raku/ch-1.raku
@@ -0,0 +1,5 @@
+#!/bin/env raku
+
+unit sub MAIN(*@ints);
+
+put @ints.pairs.map({ .value² if +@ints %% (.key + 1) }).sum;
diff --git a/challenge-252/feng-chang/raku/ch-2.raku b/challenge-252/feng-chang/raku/ch-2.raku
new file mode 100755
index 0000000000..c6767855f5
--- /dev/null
+++ b/challenge-252/feng-chang/raku/ch-2.raku
@@ -0,0 +1,9 @@
+#!/bin/env raku
+
+unit sub MAIN($n where * > 0);
+
+put solve($n, 1).join(' ');
+
+multi solve(0, $) { () }
+multi solve(1, $) { 0 }
+multi solve($n, $i) { $i, -$i, |solve($n-2, $i+1) }
diff --git a/challenge-252/feng-chang/raku/test.raku b/challenge-252/feng-chang/raku/test.raku
new file mode 100755
index 0000000000..5df710a5b0
--- /dev/null
+++ b/challenge-252/feng-chang/raku/test.raku
@@ -0,0 +1,32 @@
+#!/bin/env raku
+
+# The Weekly Challenge 252
+use Test;
+
+sub pwc-test(Str:D $script, Bool :$deeply? = False, *@input) {
+ my ($expect, $assertion) = @input.splice(*-2, 2);
+ my $p = run $script, |@input, :out;
+ if $deeply {
+ is-deeply $p.out.slurp(:close).chomp.words.Bag, $expect, $assertion;
+ } else {
+ is $p.out.slurp(:close).chomp, $expect, $assertion;
+ }
+}
+
+# Task 1, Special Numbers
+pwc-test './ch-1.raku', |<1 2 3 4>, 21, 'Special Numbers: (1, 2, 3, 4) => 21';
+pwc-test './ch-1.raku', |<2 7 1 19 18 3>, 63, 'Special Numbers: (2, 7, 1, 19, 18, 3) => 63';
+
+sub pwc252-p2-test(Str:D $script, $n) {
+ my $p = run $script, $n, :out;
+ my @ints = +«$p.out.slurp(:close).chomp.words;
+
+ ok (@ints.all ~~ Int and @ints.sum == 0 and +@ints.unique == +@ints), "$n => ({@ints.join(', ')})";
+}
+
+# Task 2, Unique Sum Zero
+pwc252-p2-test './ch-2.raku', 5;
+pwc252-p2-test './ch-2.raku', 3;
+pwc252-p2-test './ch-2.raku', 1;
+
+done-testing;