From 5f78067ad5ca27c51b3552cabb519d438f1f31b7 Mon Sep 17 00:00:00 2001 From: Mark Anderson Date: Mon, 13 Oct 2025 11:36:20 +0000 Subject: Challenge 343 Solutions (Raku) --- challenge-343/mark-anderson/raku/ch-1.raku | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/challenge-343/mark-anderson/raku/ch-1.raku b/challenge-343/mark-anderson/raku/ch-1.raku index 6d33d7d896..756460f1e5 100644 --- a/challenge-343/mark-anderson/raku/ch-1.raku +++ b/challenge-343/mark-anderson/raku/ch-1.raku @@ -1,30 +1,13 @@ #!/usr/bin/env raku use Test; -is zero-friend(4, 2, -1, 3, -2), 1; -is zero-friend(-5, 5, -3, 3, -1, 1), 1; -is zero-friend(7, -3, 0, 2, -8), 0; -is zero-friend(-2, -5, -1, -8), 1; -is zero-friend(-2, 2, -4, 4, -1, 1), 1; - -is zero-friend-alt(4, 2, -1, 3, -2), -1; -is zero-friend-alt(-5, 5, -3, 3, -1, 1), 1; -is zero-friend-alt(7, -3, 0, 2, -8), 0; -is zero-friend-alt(-2, -5, -1, -8), -1; -is zero-friend-alt(-2, 2, -4, 4, -1, 1), 1; +is zero-friend(4, 2, -1, 3, -2), 1; +is zero-friend(-5, 5, -3, 3, -1, 1), 1; +is zero-friend(7, -3, 0, 2, -8), 0; +is zero-friend(-2, -5, -1, -8), 1; +is zero-friend(-2, 2, -4, 4, -1, 1), 1; sub zero-friend(+@nums) { - @nums.map(*.abs).min -} - -# I think this alternate solution matches the instructions better. -# I meant to email Mohammad for clarification before the deadline -# but I forgot. - -sub zero-friend-alt(+@nums) -{ - my %c := { -1 => [], 0 => [], 1 => [] } - %c = @nums.classify: { .sign }, :into(%c); - (%c<-1>.max, %c<0>.min, %c<1>.min).sort({ .abs, -.sign }).head + @nums.map(*.abs).min } -- cgit