aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-05-20 09:09:59 +0100
committerGitHub <noreply@github.com>2025-05-20 09:09:59 +0100
commit7c5421ad565272dc2ad58db46a0e48e5f35f507d (patch)
treeb8bdcebb07cf7d991dab871a0e8404f0115d1f03
parent26ba89d6d3fa0ab10e9d854f825237166d490377 (diff)
parent16dce2351be4f85df717afaae3b5353f5aa6be68 (diff)
downloadperlweeklychallenge-club-7c5421ad565272dc2ad58db46a0e48e5f35f507d.tar.gz
perlweeklychallenge-club-7c5421ad565272dc2ad58db46a0e48e5f35f507d.tar.bz2
perlweeklychallenge-club-7c5421ad565272dc2ad58db46a0e48e5f35f507d.zip
Merge pull request #12047 from seaker/master
challenge 322, raku solutions
-rwxr-xr-xchallenge-322/feng-chang/raku/ch-1.raku5
-rwxr-xr-xchallenge-322/feng-chang/raku/ch-2.raku6
-rwxr-xr-xchallenge-322/feng-chang/raku/ch-2a.raku5
-rwxr-xr-xchallenge-322/feng-chang/raku/test.raku28
4 files changed, 44 insertions, 0 deletions
diff --git a/challenge-322/feng-chang/raku/ch-1.raku b/challenge-322/feng-chang/raku/ch-1.raku
new file mode 100755
index 0000000000..4f8f275faa
--- /dev/null
+++ b/challenge-322/feng-chang/raku/ch-1.raku
@@ -0,0 +1,5 @@
+#!/bin/env raku
+
+unit sub MAIN(Str:D $s, UInt:D $size);
+
+put $s.comb(/<-[-]>/).reverse.rotor($size, :partial).map(*.reverse.join).reverse.join('-');
diff --git a/challenge-322/feng-chang/raku/ch-2.raku b/challenge-322/feng-chang/raku/ch-2.raku
new file mode 100755
index 0000000000..536708961e
--- /dev/null
+++ b/challenge-322/feng-chang/raku/ch-2.raku
@@ -0,0 +1,6 @@
+#!/bin/env raku
+
+unit sub MAIN(*@ints);
+
+my @ints_ = @ints.sort.unique;
+put @ints.map({ @ints_.first($_, :k) + 1 });
diff --git a/challenge-322/feng-chang/raku/ch-2a.raku b/challenge-322/feng-chang/raku/ch-2a.raku
new file mode 100755
index 0000000000..fb6f231ab3
--- /dev/null
+++ b/challenge-322/feng-chang/raku/ch-2a.raku
@@ -0,0 +1,5 @@
+#!/bin/env raku
+
+unit sub MAIN(*@ints);
+
+put @ints.sort.unique.antipairs.Hash{ @ints } »+» 1;
diff --git a/challenge-322/feng-chang/raku/test.raku b/challenge-322/feng-chang/raku/test.raku
new file mode 100755
index 0000000000..feb9a3d165
--- /dev/null
+++ b/challenge-322/feng-chang/raku/test.raku
@@ -0,0 +1,28 @@
+#!/bin/env raku
+
+# The Weekly Challenge 322
+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, String Format
+pwc-test './ch-1.raku', 'ABC-D-E-F', 3, 'ABC-DEF', 'String Format: $str="ABC-D-E-F",$i=3 => ABC-DEF';
+pwc-test './ch-1.raku', 'A-BC-D-E', 2, 'A-BC-DE', 'String Format: $str="A-BC-D-E", $i=2 => A-BC-DE';
+pwc-test './ch-1.raku', '--', '-A-B-CD-E', 4, 'A-BCDE', 'String Format: $str="-A-B-CD-E",$i=4 => A-BCDE';
+
+# Task 2, Rank Array
+pwc-test './ch-2.raku', <55 22 44 33>, '4 1 3 2', 'Rank Array: (55,22,44,33) => (4,1,3,2)';
+pwc-test './ch-2.raku', <10 10 10>, '1 1 1', 'Rank Array: (10,10,10) => (1,1,1)';
+pwc-test './ch-2.raku', <5 1 1 4 3>, '4 1 1 3 2', 'Rank Array: (5,1,1,4,3) => (4,1,1,3,2)';
+
+pwc-test './ch-2a.raku', <55 22 44 33>, '4 1 3 2', 'Rank Array: (55,22,44,33) => (4,1,3,2)';
+pwc-test './ch-2a.raku', <10 10 10>, '1 1 1', 'Rank Array: (10,10,10) => (1,1,1)';
+pwc-test './ch-2a.raku', <5 1 1 4 3>, '4 1 1 3 2', 'Rank Array: (5,1,1,4,3) => (4,1,1,3,2)';