aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author冯昶 <fengchang@novel-supertv.com>2024-03-18 15:55:29 +0800
committer冯昶 <fengchang@novel-supertv.com>2024-03-18 15:55:29 +0800
commit4a75f843201aae3aab3d097ece0436c6a537304b (patch)
tree65f94f7ddbe7ecd6423fa01f52242af4c3ccc864
parent1f6485c5ccc65469caa5e55dd5c74f24c4bf1ed9 (diff)
downloadperlweeklychallenge-club-4a75f843201aae3aab3d097ece0436c6a537304b.tar.gz
perlweeklychallenge-club-4a75f843201aae3aab3d097ece0436c6a537304b.tar.bz2
perlweeklychallenge-club-4a75f843201aae3aab3d097ece0436c6a537304b.zip
challenge 261, raku solutions
-rwxr-xr-xchallenge-261/feng-chang/raku/ch-1.raku5
-rwxr-xr-xchallenge-261/feng-chang/raku/ch-2.raku7
-rwxr-xr-xchallenge-261/feng-chang/raku/test.raku25
3 files changed, 37 insertions, 0 deletions
diff --git a/challenge-261/feng-chang/raku/ch-1.raku b/challenge-261/feng-chang/raku/ch-1.raku
new file mode 100755
index 0000000000..b913f2f35c
--- /dev/null
+++ b/challenge-261/feng-chang/raku/ch-1.raku
@@ -0,0 +1,5 @@
+#!/bin/env raku
+
+unit sub MAIN(*@ints);
+
+put @ints.sum - @ints».comb».sum.sum;
diff --git a/challenge-261/feng-chang/raku/ch-2.raku b/challenge-261/feng-chang/raku/ch-2.raku
new file mode 100755
index 0000000000..fbb2ac591f
--- /dev/null
+++ b/challenge-261/feng-chang/raku/ch-2.raku
@@ -0,0 +1,7 @@
+#!/bin/env raku
+
+unit sub MAIN(*@ints);
+
+my $start = @ints.pop;
+$start *= 2 while @ints.grep($start);
+put $start;
diff --git a/challenge-261/feng-chang/raku/test.raku b/challenge-261/feng-chang/raku/test.raku
new file mode 100755
index 0000000000..d78a96d7db
--- /dev/null
+++ b/challenge-261/feng-chang/raku/test.raku
@@ -0,0 +1,25 @@
+#!/bin/env raku
+
+# The Weekly Challenge 261
+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, Element Digit Sum
+pwc-test './ch-1.raku', <1 2 3 45>, 36, 'Element Digit Sum: (1,2,3,45) => 36';
+pwc-test './ch-1.raku', <1 12 3>, 9, 'Element Digit Sum: (1,12,3) => 9';
+pwc-test './ch-1.raku', <1 2 3 4>, 0, 'Element Digit Sum: (1,2,3,4) => 0';
+pwc-test './ch-1.raku', <236 416 336 350>, 1296, 'Element Digit Sum: (236, 416, 336, 350) => 1296';
+
+# Task 2, Multiply by Two
+pwc-test './ch-2.raku', <5 3 6 1 12>, 3, 24, 'Multiply by Two: @ints=(5,3,6,1,12), $start=3 => 24';
+pwc-test './ch-2.raku', <1 2 4 3>, 1, 8, 'Multiply by Two: @ints=(1,2,4,3), $start=1 => 8';
+pwc-test './ch-2.raku', <5 6 7>, 2, 2, 'Multiply by Two: @ints=(5,6,7), $start=2 => 2';