aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author冯昶 <fengchang@novel-supertv.com>2024-01-16 10:42:08 +0800
committer冯昶 <fengchang@novel-supertv.com>2024-01-16 10:42:08 +0800
commit116ef5347bad7190e88ed2e8d40097f8978645bf (patch)
tree0ee1839a80bb0405aa7fb31c7f9f19d12610ae4e
parent4497a5f59bd9de56f576e49baf32528243699268 (diff)
downloadperlweeklychallenge-club-116ef5347bad7190e88ed2e8d40097f8978645bf.tar.gz
perlweeklychallenge-club-116ef5347bad7190e88ed2e8d40097f8978645bf.tar.bz2
perlweeklychallenge-club-116ef5347bad7190e88ed2e8d40097f8978645bf.zip
challenge 249, raku solutions
-rwxr-xr-xchallenge-249/feng-chang/raku/ch-1.raku10
-rwxr-xr-xchallenge-249/feng-chang/raku/ch-2.raku13
-rwxr-xr-xchallenge-249/feng-chang/raku/test.raku25
3 files changed, 48 insertions, 0 deletions
diff --git a/challenge-249/feng-chang/raku/ch-1.raku b/challenge-249/feng-chang/raku/ch-1.raku
new file mode 100755
index 0000000000..a04c99fa55
--- /dev/null
+++ b/challenge-249/feng-chang/raku/ch-1.raku
@@ -0,0 +1,10 @@
+#!/bin/env raku
+
+unit sub MAIN(*@ints);
+
+@ints = (+«@ints).sort;
+if +@ints %% 2 and @ints.rotor(2).map({ .[0] == .[1] }).all {
+ put @ints.rotor(2).map({ "({.[0]}, {.[1]})" }).join(', ');
+} else {
+ put '()';
+}
diff --git a/challenge-249/feng-chang/raku/ch-2.raku b/challenge-249/feng-chang/raku/ch-2.raku
new file mode 100755
index 0000000000..c0b436a5f8
--- /dev/null
+++ b/challenge-249/feng-chang/raku/ch-2.raku
@@ -0,0 +1,13 @@
+#!/bin/env raku
+
+unit sub MAIN(Str:D $s where *.comb.all eq 'D'|'I');
+
+my @a = 0..$s.chars;
+my @b = gather {
+ for $s.comb {
+ when 'D' { take @a.pop }
+ when 'I' { take @a.shift }
+ }
+ take @a[0];
+}
+put '(', @b.join(', ') , ')';
diff --git a/challenge-249/feng-chang/raku/test.raku b/challenge-249/feng-chang/raku/test.raku
new file mode 100755
index 0000000000..6ad7b4930d
--- /dev/null
+++ b/challenge-249/feng-chang/raku/test.raku
@@ -0,0 +1,25 @@
+#!/bin/env raku
+
+# The Weekly Challenge 249
+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, Equal Pairs
+pwc-test './ch-1.raku', |<3 2 3 2 2 2>, '(2, 2), (2, 2), (3, 3)', 'Equal Pairs: (3, 2, 3, 2, 2, 2) => (2, 2), (2, 2), (3, 3)';
+pwc-test './ch-1.raku', |<1 2 3 4>, '()', 'Equal Pairs: (1, 2, 3, 4) => ()';
+
+# Task 2, DI String Match
+pwc-test './ch-2.raku', 'IDID', '(0, 4, 1, 3, 2)', 'DI String Match: IDID => (0, 4, 1, 3, 2)';
+pwc-test './ch-2.raku', 'III', '(0, 1, 2, 3)', 'DI String Match: III => (0, 1, 2, 3)';
+pwc-test './ch-2.raku', 'DDI', '(3, 2, 0, 1)', 'DI String Match: DDI => (3, 2, 0, 1)';
+
+done-testing;