aboutsummaryrefslogtreecommitdiff
path: root/challenge-262
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-03-26 11:34:33 +0000
committerGitHub <noreply@github.com>2024-03-26 11:34:33 +0000
commite8eceb5e868d21a75a130bf77c75b984e0b7506b (patch)
treefcb8ec2eb897d6ae70b3b9f0888e260d2bf7047a /challenge-262
parent7a62f74146039e58be63822678f96b98bd27d1de (diff)
parent67fef37926d79624e95d5dcf24d7457eb9c38ca9 (diff)
downloadperlweeklychallenge-club-e8eceb5e868d21a75a130bf77c75b984e0b7506b.tar.gz
perlweeklychallenge-club-e8eceb5e868d21a75a130bf77c75b984e0b7506b.tar.bz2
perlweeklychallenge-club-e8eceb5e868d21a75a130bf77c75b984e0b7506b.zip
Merge pull request #9811 from seaker/master
challenge 262, raku solutions
Diffstat (limited to 'challenge-262')
-rwxr-xr-xchallenge-262/feng-chang/raku/ch-1.raku6
-rwxr-xr-xchallenge-262/feng-chang/raku/ch-1a.raku8
-rwxr-xr-xchallenge-262/feng-chang/raku/ch-2.raku6
-rwxr-xr-xchallenge-262/feng-chang/raku/test.raku27
4 files changed, 47 insertions, 0 deletions
diff --git a/challenge-262/feng-chang/raku/ch-1.raku b/challenge-262/feng-chang/raku/ch-1.raku
new file mode 100755
index 0000000000..e1b106e464
--- /dev/null
+++ b/challenge-262/feng-chang/raku/ch-1.raku
@@ -0,0 +1,6 @@
+#!/bin/env raku
+
+unit sub MAIN(*@ints);
+
+my \posis = +@ints.grep(*>0);
+put max(posis, +@ints - posis);
diff --git a/challenge-262/feng-chang/raku/ch-1a.raku b/challenge-262/feng-chang/raku/ch-1a.raku
new file mode 100755
index 0000000000..4b0b8f4ea7
--- /dev/null
+++ b/challenge-262/feng-chang/raku/ch-1a.raku
@@ -0,0 +1,8 @@
+#!/bin/env raku
+
+unit sub MAIN(*@ints);
+
+@ints ==>
+grep(* > 0) ==>
+my @v; max(+@v, +@ints - +@v) ==>
+put()
diff --git a/challenge-262/feng-chang/raku/ch-2.raku b/challenge-262/feng-chang/raku/ch-2.raku
new file mode 100755
index 0000000000..97972e706b
--- /dev/null
+++ b/challenge-262/feng-chang/raku/ch-2.raku
@@ -0,0 +1,6 @@
+#!/bin/env raku
+
+unit sub MAIN(*@ints);
+
+my \k = @ints.pop;
+put +(^+@ints).combinations(2).grep(-> (\a,\b) { @ints[a] == @ints[b] and a*b %% k });
diff --git a/challenge-262/feng-chang/raku/test.raku b/challenge-262/feng-chang/raku/test.raku
new file mode 100755
index 0000000000..6492833931
--- /dev/null
+++ b/challenge-262/feng-chang/raku/test.raku
@@ -0,0 +1,27 @@
+#!/bin/env raku
+
+# The Weekly Challenge 262
+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, Max Positive Negative
+pwc-test './ch-1.raku', <-- -3 1 2 -1 3 -2 4>, 4, 'Max Positive Negative: (-3,1,2,-1,3,-2,4) => 4';
+pwc-test './ch-1.raku', <-- -1 -2 -3 1>, 3, 'Max Positive Negative: (-1,-2,-3,1) => 3';
+pwc-test './ch-1.raku', <-- 1 2>, 2, 'Max Positive Negative: (1,2) => 2';
+
+pwc-test './ch-1a.raku', <-- -3 1 2 -1 3 -2 4>, 4, 'Max Positive Negative: (-3,1,2,-1,3,-2,4) => 4';
+pwc-test './ch-1a.raku', <-- -1 -2 -3 1>, 3, 'Max Positive Negative: (-1,-2,-3,1) => 3';
+pwc-test './ch-1a.raku', <-- 1 2>, 2, 'Max Positive Negative: (1,2) => 2';
+
+# Task 2, Count Equal Divisible
+pwc-test './ch-2.raku', <3 1 2 2 2 1 3>, 2, 4, 'Count Equal Divisible: @ints=(3,1,2,2,2,1,3), $k=2 => 4';
+pwc-test './ch-2.raku', <1 2 3>, 1, 0, 'Count Equal Divisible: @ints=(1,2,3), $k=1 => 0';