aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBarrOff <58253563+BarrOff@users.noreply.github.com>2025-10-20 00:23:05 +0200
committerBarrOff <58253563+BarrOff@users.noreply.github.com>2025-10-20 00:23:05 +0200
commit242b789f98aec2f6b0296efb7aabeeedf6e2de71 (patch)
tree2017f2be335868b7a74d8a4a86064f9dcf183d19
parent4df5972a67e3e2c0d24f9b50699058f0b8f77118 (diff)
downloadperlweeklychallenge-club-242b789f98aec2f6b0296efb7aabeeedf6e2de71.tar.gz
perlweeklychallenge-club-242b789f98aec2f6b0296efb7aabeeedf6e2de71.tar.bz2
perlweeklychallenge-club-242b789f98aec2f6b0296efb7aabeeedf6e2de71.zip
feat: add solution for challenge 343 from BarrOff
-rw-r--r--challenge-343/barroff/raku/ch-1.p627
1 files changed, 27 insertions, 0 deletions
diff --git a/challenge-343/barroff/raku/ch-1.p6 b/challenge-343/barroff/raku/ch-1.p6
new file mode 100644
index 0000000000..eba555a481
--- /dev/null
+++ b/challenge-343/barroff/raku/ch-1.p6
@@ -0,0 +1,27 @@
+#!/usr/bin/env raku
+
+use v6.d;
+
+sub zero-friend(@nums --> Int) {
+ return 0 if 0 ∈ @nums;
+ my $above = min(grep({ $_ > 0 }, @nums));
+ my $below = max(grep({ $_ < 0 }, @nums));
+ return min($above, abs($below))
+}
+
+#| Run test cases
+multi sub MAIN('test') {
+ use Test;
+ plan 5;
+
+ is zero-friend([4, 2, -1, 3, -2]), 1, 'works for [4, 2, -1, 3, -2]';
+ is zero-friend([-5, 5, -3, 3, -1, 1]), 1, 'works for [-5, 5, -3, 3, -1, 1]';
+ is zero-friend([7, -3, 0, 2, -8]), 0, 'works for [7, -3, 0, 2, -8]';
+ is zero-friend([-2, -5, -1, -8]), 1, 'works for [-2, -5, -1, -8]';
+ is zero-friend([-2, 2, -4, 4, -1, 1]), 1, 'works for [-2, 2, -4, 4, -1, 1]';
+}
+
+#| Take user provided numbers 5 9 3 4 6
+multi sub MAIN(*@nums) {
+ say zero-friend(@nums);
+}