aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author冯昶 <fengchang@novel-supertv.com>2025-05-05 18:24:14 +0800
committer冯昶 <fengchang@novel-supertv.com>2025-05-05 18:24:14 +0800
commitf29aefe932fd6c0c0b64831700c7966477c94410 (patch)
tree755c7367e1da87a26ec635accd38225e4dafe3fa
parent4865a9cce3c19c5a1def20017a083f17ef9a0809 (diff)
downloadperlweeklychallenge-club-f29aefe932fd6c0c0b64831700c7966477c94410.tar.gz
perlweeklychallenge-club-f29aefe932fd6c0c0b64831700c7966477c94410.tar.bz2
perlweeklychallenge-club-f29aefe932fd6c0c0b64831700c7966477c94410.zip
challenge 320, raku solutions
-rwxr-xr-xchallenge-320/feng-chang/raku/ch-1.raku5
-rwxr-xr-xchallenge-320/feng-chang/raku/ch-2.raku5
-rwxr-xr-xchallenge-320/feng-chang/raku/test.raku24
3 files changed, 34 insertions, 0 deletions
diff --git a/challenge-320/feng-chang/raku/ch-1.raku b/challenge-320/feng-chang/raku/ch-1.raku
new file mode 100755
index 0000000000..fcb275a500
--- /dev/null
+++ b/challenge-320/feng-chang/raku/ch-1.raku
@@ -0,0 +1,5 @@
+#!/bin/env raku
+
+unit sub MAIN(*@ints);
+
+put max(+@ints.grep(* > 0), +@ints.grep(* < 0));
diff --git a/challenge-320/feng-chang/raku/ch-2.raku b/challenge-320/feng-chang/raku/ch-2.raku
new file mode 100755
index 0000000000..9467265427
--- /dev/null
+++ b/challenge-320/feng-chang/raku/ch-2.raku
@@ -0,0 +1,5 @@
+#!/bin/env raku
+
+unit sub MAIN(*@ints where .all > 0);
+
+put abs(@ints.sum - @ints».comb.flat(:hammer).sum);
diff --git a/challenge-320/feng-chang/raku/test.raku b/challenge-320/feng-chang/raku/test.raku
new file mode 100755
index 0000000000..081b6d6239
--- /dev/null
+++ b/challenge-320/feng-chang/raku/test.raku
@@ -0,0 +1,24 @@
+#!/bin/env raku
+
+# The Weekly Challenge 320
+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, Maximum Count
+pwc-test './ch-1.raku', '--', <-3 -2 -1 1 2 3>, 3, 'Maximum Count: (-3,-2,-1,1,2,3) => 3';
+pwc-test './ch-1.raku', '--', <-2 -1 0 0 1>, 2, 'Maximum Count: (-2,-1,0,0,1) => 2';
+pwc-test './ch-1.raku', '--', <1 2 3 4>, 4, 'Maximum Count: (1,2,3,4) => 4';
+
+# Task 2, Sum Difference
+pwc-test './ch-2.raku', <1 23 4 5>, 18, 'Sum Difference: (1,23,4,5) => 18';
+pwc-test './ch-2.raku', <1 2 3 4 5>, 0, 'Sum Difference: (1,2,3,4,5) => 0';
+pwc-test './ch-2.raku', <1 2 34>, 27, 'Sum Difference: (1,2,34) => 27';