aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-256/feng-chang/raku/ch-1.raku6
-rwxr-xr-xchallenge-256/feng-chang/raku/ch-2.raku6
-rwxr-xr-xchallenge-256/feng-chang/raku/test.raku24
-rwxr-xr-xchallenge-257/feng-chang/raku/ch-1.raku5
-rwxr-xr-xchallenge-257/feng-chang/raku/ch-2.raku30
-rwxr-xr-xchallenge-257/feng-chang/raku/test.raku31
6 files changed, 102 insertions, 0 deletions
diff --git a/challenge-256/feng-chang/raku/ch-1.raku b/challenge-256/feng-chang/raku/ch-1.raku
new file mode 100755
index 0000000000..a50027a15d
--- /dev/null
+++ b/challenge-256/feng-chang/raku/ch-1.raku
@@ -0,0 +1,6 @@
+#!/bin/env raku
+
+unit sub MAIN(*@strs);
+
+my %s is Set = @strs.grep({ $_ ne .flip });
+put +%s.keys.grep({ %s{.flip} }) / 2;
diff --git a/challenge-256/feng-chang/raku/ch-2.raku b/challenge-256/feng-chang/raku/ch-2.raku
new file mode 100755
index 0000000000..b487c7c3ef
--- /dev/null
+++ b/challenge-256/feng-chang/raku/ch-2.raku
@@ -0,0 +1,6 @@
+#!/bin/env raku
+
+unit sub MAIN(Str:D \s1, Str:D \s2);
+
+my \len = (s1, s2)».chars.min;
+put (s1.comb Z~ s2.comb).join ~ substr(s1, len) ~ substr(s2, len);
diff --git a/challenge-256/feng-chang/raku/test.raku b/challenge-256/feng-chang/raku/test.raku
new file mode 100755
index 0000000000..83cd784cba
--- /dev/null
+++ b/challenge-256/feng-chang/raku/test.raku
@@ -0,0 +1,24 @@
+#!/bin/env raku
+
+# The Weekly Challenge 256
+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 Pairs
+pwc-test './ch-1.raku', <ab de ed bc>, 1, 'Maximum Pairs: "ab", "de", "ed", "bc" => 1';
+pwc-test './ch-1.raku', <aa ba cd ed>, 0, 'Maximum Pairs: "aa", "ba", "cd", "ed" => 0';
+pwc-test './ch-1.raku', <uv qp st vu mn pq>, 2, 'Maximum Pairs: "uv", "qp", "st", "vu", "mn", "pq" => 2';
+
+# Task 2, Merge Strings
+pwc-test './ch-2.raku', <abcd 1234>, 'a1b2c3d4', 'Merge Strings: "abcd", "1234" => a1b2c3d4';
+pwc-test './ch-2.raku', <abc 12345>, 'a1b2c345', 'Merge Strings: "abc", "12345" => a1b2c345';
+pwc-test './ch-2.raku', <abcde 123>, 'a1b2c3de', 'Merge Strings: "abcde", "123" => a1b2c3de';
diff --git a/challenge-257/feng-chang/raku/ch-1.raku b/challenge-257/feng-chang/raku/ch-1.raku
new file mode 100755
index 0000000000..ff4017e196
--- /dev/null
+++ b/challenge-257/feng-chang/raku/ch-1.raku
@@ -0,0 +1,5 @@
+#!/bin/env raku
+
+unit sub MAIN(*@ints);
+
+put @ints.map(-> \a { +@ints.grep(* < a) }).join(', ');
diff --git a/challenge-257/feng-chang/raku/ch-2.raku b/challenge-257/feng-chang/raku/ch-2.raku
new file mode 100755
index 0000000000..eb269c81e0
--- /dev/null
+++ b/challenge-257/feng-chang/raku/ch-2.raku
@@ -0,0 +1,30 @@
+#!/bin/env raku
+
+use MONKEY-SEE-NO-EVAL;
+
+unit sub MAIN(Str:D $s);
+
+my @M;
+EVAL "@M = $s";
+put +is-reduced-echelon-matrix(@M);
+
+sub is-reduced-echelon-matrix(@M --> Bool:D) {
+ my $solid-row = +@M;
+ --$solid-row while @M[$solid-row - 1].all == 0;
+
+ my $leading-col = -1;
+ for ^$solid-row -> \row {
+ with @M[row] {
+ return False if .all == 0;
+
+ my \col = .first(?*, :k);
+ return False if .[col] != 1;
+
+ return False if col ≤ $leading-col;
+ $leading-col = col;
+ }
+ return False unless @M[^row;$leading-col].all == 0;
+ }
+
+ True
+}
diff --git a/challenge-257/feng-chang/raku/test.raku b/challenge-257/feng-chang/raku/test.raku
new file mode 100755
index 0000000000..090bca0c7e
--- /dev/null
+++ b/challenge-257/feng-chang/raku/test.raku
@@ -0,0 +1,31 @@
+#!/bin/env raku
+
+# The Weekly Challenge 257
+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', <5 2 1 6>, '2, 1, 0, 3', 'Smaller than Current: 5, 2, 1, 6 => 2, 1, 0, 3';
+pwc-test './ch-1.raku', <1 2 0 3>, '1, 2, 0, 3', 'Smaller than Current: 1, 2, 0, 3 => 1, 2, 0, 3';
+pwc-test './ch-1.raku', <0 1>, '0, 1', 'Smaller than Current: 0, 1 => 0, 1';
+pwc-test './ch-1.raku', <9 4 9 2>, '2, 1, 2, 0', 'Smaller than Current: 9, 4, 9, 2 => 2, 1, 2, 0';
+
+# Task 2, Reduced Row Echelon
+pwc-test './ch-2.raku', '[1,0,0],[0,0,0],[0,1,0]', 0, 'Reduced Row Echelon: [1,0,0],[0,0,0],[0,1,0] => 0';
+pwc-test './ch-2.raku', '[1,0,0],[0,1,0],[0,0,0]', 1, 'Reduced Row Echelon: [1,0,0],[0,1,0],[0,0,0] => 1';
+pwc-test './ch-2.raku', '[1,0,0],[0,2,0],[0,0,0]', 0, 'Reduced Row Echelon: [1,0,0],[0,2,0],[0,0,0] => 0';
+pwc-test './ch-2.raku', '[1,0,0,1],[0,1,0,2],[0,0,1,3]', 1, 'Reduced Row Echelon: [1,0,0,1],[0,1,0,2],[0,0,1,3] => 1';
+pwc-test './ch-2.raku', '[0,1,-2,0,1],[0,0,0,1,3],[0,0,0,0,0],[0,0,0,0,0]', 1, 'Reduced Row Echelon: [0,1,-2,0,1],[0,0,0,1,3],[0,0,0,0,0],[0,0,0,0,0] => 1';
+pwc-test './ch-2.raku', '[1,0,0,4],[0,1,0,7],[0,0,1,-1]', 1, 'Reduced Row Echelon: [1,0,0,4],[0,1,0,7],[0,0,1,-1] => 1';
+pwc-test './ch-2.raku', '[0,1,-2,0,1],[0,0,0,0,0],[0,0,0,1,3],[0,0,0,0,0]', 0, 'Reduced Row Echelon: [0,1,-2,0,1],[0,0,0,0,0],[0,0,0,1,3],[0,0,0,0,0] => 0';
+pwc-test './ch-2.raku', '[0,1,0],[1,0,0],[0,0,0]', 0, 'Reduced Row Echelon: [0,1,0],[1,0,0],[0,0,0] => 0';
+pwc-test './ch-2.raku', '[4,0,0,0],[0,1,0,7],[0,0,1,-1]', 0, 'Reduced Row Echelon: [4,0,0,0],[0,1,0,7],[0,0,1,-1] => 0';