aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author冯昶 <fengchang@novel-supertv.com>2024-05-13 16:21:23 +0800
committer冯昶 <fengchang@novel-supertv.com>2024-05-13 16:21:23 +0800
commit40a0178c372b824802bec1f32d773fd2bd0dc688 (patch)
tree4a2e26c02ee13e3e031dda342b997eda58c85533
parent02e309b3d451fff60404eb5ab3e539056f99ce0d (diff)
downloadperlweeklychallenge-club-40a0178c372b824802bec1f32d773fd2bd0dc688.tar.gz
perlweeklychallenge-club-40a0178c372b824802bec1f32d773fd2bd0dc688.tar.bz2
perlweeklychallenge-club-40a0178c372b824802bec1f32d773fd2bd0dc688.zip
challenge 269, raku solutions
-rwxr-xr-xchallenge-269/feng-chang/raku/ch-1.raku5
-rwxr-xr-xchallenge-269/feng-chang/raku/ch-2.raku9
-rwxr-xr-xchallenge-269/feng-chang/raku/test.raku24
3 files changed, 38 insertions, 0 deletions
diff --git a/challenge-269/feng-chang/raku/ch-1.raku b/challenge-269/feng-chang/raku/ch-1.raku
new file mode 100755
index 0000000000..29ebaa1767
--- /dev/null
+++ b/challenge-269/feng-chang/raku/ch-1.raku
@@ -0,0 +1,5 @@
+#!/bin/env raku
+
+unit sub MAIN(*@ints);
+
+put so +@ints.grep(* %% 2) > 1;
diff --git a/challenge-269/feng-chang/raku/ch-2.raku b/challenge-269/feng-chang/raku/ch-2.raku
new file mode 100755
index 0000000000..6a28adb1d6
--- /dev/null
+++ b/challenge-269/feng-chang/raku/ch-2.raku
@@ -0,0 +1,9 @@
+#!/bin/env raku
+
+unit sub MAIN(*@ints where +@ints ≥ 2);
+
+my (@a, @b);
+@a.push(@ints.shift);
+@b.push(@ints.shift);
+@a[*-1] > @b[*-1] ?? @a.push($_) !! @b.push($_) for @ints;
+put "{@a} {@b}";
diff --git a/challenge-269/feng-chang/raku/test.raku b/challenge-269/feng-chang/raku/test.raku
new file mode 100755
index 0000000000..8a52c9ad2f
--- /dev/null
+++ b/challenge-269/feng-chang/raku/test.raku
@@ -0,0 +1,24 @@
+#!/bin/env raku
+
+# The Weekly Challenge 269
+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, Bitwise OR
+pwc-test './ch-1.raku', <1 2 3 4 5>, 'True', 'Bitwise OR: (1,2,3,4,5) => True';
+pwc-test './ch-1.raku', <2 3 8 16>, 'True', 'Bitwise OR: (2,3,8,16) => True';
+pwc-test './ch-1.raku', <1 2 5 7 9>, 'False', 'Bitwise OR: (1,2,5,7,9) => False';
+
+# Task 2, Distribute Elements
+pwc-test './ch-2.raku', <2 1 3 4 5>, '2 3 4 5 1', 'Distribute Elements: (2,1,3,4,5) => (2,3,4,5,1)';
+pwc-test './ch-2.raku', <3 2 4>, '3 4 2', 'Distribute Elements: (3,2,4) => (3,4,2)';
+pwc-test './ch-2.raku', <5 4 3 8>, '5 3 4 8', 'Distribute Elements: (5,4,3,8) => (5,3,4,8)';