aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author冯昶 <fengchang@novel-supertv.com>2025-09-01 14:52:18 +0800
committer冯昶 <fengchang@novel-supertv.com>2025-09-01 14:52:18 +0800
commitccc5bfa29bdceb31256297775cf46ff02c7d2513 (patch)
treed272604bd3352b0a9541f55972bab90c70f12b60
parente80c93c27044ee16a834a9ee64a0087c1c7d0b1d (diff)
downloadperlweeklychallenge-club-ccc5bfa29bdceb31256297775cf46ff02c7d2513.tar.gz
perlweeklychallenge-club-ccc5bfa29bdceb31256297775cf46ff02c7d2513.tar.bz2
perlweeklychallenge-club-ccc5bfa29bdceb31256297775cf46ff02c7d2513.zip
challenge 337, raku solutions
-rwxr-xr-xchallenge-337/feng-chang/raku/ch-1.raku5
-rwxr-xr-xchallenge-337/feng-chang/raku/ch-2.raku13
-rwxr-xr-xchallenge-337/feng-chang/raku/test.raku28
3 files changed, 46 insertions, 0 deletions
diff --git a/challenge-337/feng-chang/raku/ch-1.raku b/challenge-337/feng-chang/raku/ch-1.raku
new file mode 100755
index 0000000000..56cbc16912
--- /dev/null
+++ b/challenge-337/feng-chang/raku/ch-1.raku
@@ -0,0 +1,5 @@
+#!/bin/env raku
+
+unit sub MAIN(*@num1);
+
+put @num1.map({ @num1.sort.first($_, :k) });
diff --git a/challenge-337/feng-chang/raku/ch-2.raku b/challenge-337/feng-chang/raku/ch-2.raku
new file mode 100755
index 0000000000..beb6ca7ba2
--- /dev/null
+++ b/challenge-337/feng-chang/raku/ch-2.raku
@@ -0,0 +1,13 @@
+#!/bin/env raku
+
+unit sub MAIN(UInt:D $rows, UInt:D $cols, Str:D $locations);
+
+use MONKEY-SEE-NO-EVAL;
+
+my @matrix = [0 xx $cols] xx $rows;
+my @loc = EVAL $locations;
+for @loc -> ($row, $col) {
+ @matrix[$row] »+=» 1;
+ @matrix[*;$col] »+=» 1;
+}
+put +@matrix.flat(:hammer).grep(* !%% 2);
diff --git a/challenge-337/feng-chang/raku/test.raku b/challenge-337/feng-chang/raku/test.raku
new file mode 100755
index 0000000000..75b4fcfdf4
--- /dev/null
+++ b/challenge-337/feng-chang/raku/test.raku
@@ -0,0 +1,28 @@
+#!/bin/env raku
+
+# The Weekly Challenge 337
+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, Smaller Than Current
+pwc-test './ch-1.raku', <6 5 4 8>, '2 1 0 3', 'Smaller Than Current: (6,5,4,8) => (2,1,0,3)';
+pwc-test './ch-1.raku', <7 7 7 7>, '0 0 0 0', 'Smaller Than Current: (7,7,7,7) => (0,0,0,0)';
+pwc-test './ch-1.raku', <5 4 3 2 1>, '4 3 2 1 0', 'Smaller Than Current: (5,4,3,2,1) => (4,3,2,1,0)';
+pwc-test './ch-1.raku', <-- -1 0 3 -2 1>, '1 2 4 0 3', 'Smaller Than Current: (-1,0,3,-2,1) => (1,2,4,0,3)';
+pwc-test './ch-1.raku', <0 1 1 2 0>, '0 2 2 4 0', 'Smaller Than Current: (0,1,1,2,0) => (0,2,2,4,0)';
+
+# Task 2, Odd Matrix
+pwc-test './ch-2.raku', <2 3 [0,1],[1,1]>, 6, 'Odd Matrix: $row=2, $col=3, @locations=([0,1],[1,1]) => 6';
+pwc-test './ch-2.raku', <2 2 [1,1],[0,0]>, 0, 'Odd Matrix: $row=2, $col=2, @locations=([1,1],[0,0]) => 0';
+pwc-test './ch-2.raku', <3 3 [0,0],[1,2],[2,1]>, 0, 'Odd Matrix: $row=3, $col=3, @locations=([0,0],[1,2],[2,1]) => 0';
+pwc-test './ch-2.raku', <1 5 [0,2],[0,4]>, 2, 'Odd Matrix: $row=1, $col=5, @locations=([0,2],[0,4]) => 2';
+pwc-test './ch-2.raku', <4 2 [1,0],[3,1],[2,0],[0,1]>, 8, 'Odd Matrix: $row=4, $col=2, @locations=([1,0],[3,1],[2,0],[0,1]) => 8';