diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-06-24 23:29:52 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-24 23:29:52 +0100 |
| commit | 129efeec865de25f04cc44cfacdc657b31d034ed (patch) | |
| tree | 2f046379ae070d6c8459336dff5c3f93623f45a9 | |
| parent | 99d8fa43930abb471fac2b94b68c0785619b37fc (diff) | |
| parent | 2e3cf0455510431c2b4027601ce2f2c87c02070c (diff) | |
| download | perlweeklychallenge-club-129efeec865de25f04cc44cfacdc657b31d034ed.tar.gz perlweeklychallenge-club-129efeec865de25f04cc44cfacdc657b31d034ed.tar.bz2 perlweeklychallenge-club-129efeec865de25f04cc44cfacdc657b31d034ed.zip | |
Merge pull request #12223 from ash/ash-327
Week 327, solutions in Raku by @ash
| -rw-r--r-- | challenge-327/ash/raku/ch-1.raku | 10 | ||||
| -rw-r--r-- | challenge-327/ash/raku/ch-2.raku | 13 | ||||
| -rw-r--r-- | challenge-327/ash/raku/ch-2a.raku | 12 |
3 files changed, 35 insertions, 0 deletions
diff --git a/challenge-327/ash/raku/ch-1.raku b/challenge-327/ash/raku/ch-1.raku new file mode 100644 index 0000000000..74723abdc5 --- /dev/null +++ b/challenge-327/ash/raku/ch-1.raku @@ -0,0 +1,10 @@ +# Task 1 of the Weekly Challenge 327 +# https://theweeklychallenge.org/blog/perl-weekly-challenge-327/#TASK1 + +say missing-numbers(1, 2, 1, 3, 2, 5); # 4, 6 +say missing-numbers(1, 1, 1); # 2, 3 +say missing-numbers(2, 2, 1); # 3 + +sub missing-numbers(*@data) { + (1 .. @data.elems) (-) @data +} diff --git a/challenge-327/ash/raku/ch-2.raku b/challenge-327/ash/raku/ch-2.raku new file mode 100644 index 0000000000..6946b5f2e7 --- /dev/null +++ b/challenge-327/ash/raku/ch-2.raku @@ -0,0 +1,13 @@ +# Task 2 of the Weekly Challenge 327 +# https://theweeklychallenge.org/blog/perl-weekly-challenge-327/#TASK2 + +say mad(4, 1, 2, 3); # ((4 3) (1 2) (2 3)) +say mad(1, 3, 7, 11, 15); # ((1 3)) +say mad(1, 5, 3, 8); # ((1 3) (5 3)) + +sub mad(*@data) { + my @pairs = @data.combinations(2); + my $min_diff = min(@pairs.map: {abs(.[0] - .[1])}); + + return @pairs.grep: {abs(.[0] - .[1]) == $min_diff}; +} diff --git a/challenge-327/ash/raku/ch-2a.raku b/challenge-327/ash/raku/ch-2a.raku new file mode 100644 index 0000000000..1ef1f651a8 --- /dev/null +++ b/challenge-327/ash/raku/ch-2a.raku @@ -0,0 +1,12 @@ +# Task 2 of the Weekly Challenge 327 +# https://theweeklychallenge.org/blog/perl-weekly-challenge-327/#TASK2 + +say mad(4, 1, 2, 3); # [(4 3) (1 2) (2 3)] +say mad(1, 3, 7, 11, 15); # [(1 3)] +say mad(1, 5, 3, 8); # [(1 3) (5 3)] + +sub mad(*@data) { + my $classification = @data.combinations(2).classify: {abs(.[0] - .[1])}; + + return ($classification.first: *.key == $classification.keys.min).value; +} |
