aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-05-06 15:24:44 +0100
committerGitHub <noreply@github.com>2025-05-06 15:24:44 +0100
commit2169f58b8e82f174a14103eaaea0abe3abfad6e7 (patch)
treed1c9c162de37270cc80048a7d2591876a44ca8cc
parent1fa41ffd3abb48439d78b14a2ab264bf88a1e754 (diff)
parentf0c30c4b629a73b4f38bdcc505da87e32263ad17 (diff)
downloadperlweeklychallenge-club-2169f58b8e82f174a14103eaaea0abe3abfad6e7.tar.gz
perlweeklychallenge-club-2169f58b8e82f174a14103eaaea0abe3abfad6e7.tar.bz2
perlweeklychallenge-club-2169f58b8e82f174a14103eaaea0abe3abfad6e7.zip
Merge pull request #11978 from seaker/master
Feng Chang's 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..f74aae2431
--- /dev/null
+++ b/challenge-320/feng-chang/raku/ch-1.raku
@@ -0,0 +1,5 @@
+#!/bin/env raku
+
+unit sub MAIN(*@ints);
+
+put max(+.grep(* > 0), +.grep(* < 0)) with @ints;
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..93fff615b7
--- /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 @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';