diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-06-24 23:58:35 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-24 23:58:35 +0100 |
| commit | e1863f66b8e0f2b16ef61d553baabdbe38f56a86 (patch) | |
| tree | 09caaa9bf3b4d33dc415c827cea65f8c2ca34728 | |
| parent | 56d38d532cb5ab2fef151cf8f4731e8f16c24421 (diff) | |
| parent | a0313112fc18db4458e660e926adde35653b4e26 (diff) | |
| download | perlweeklychallenge-club-e1863f66b8e0f2b16ef61d553baabdbe38f56a86.tar.gz perlweeklychallenge-club-e1863f66b8e0f2b16ef61d553baabdbe38f56a86.tar.bz2 perlweeklychallenge-club-e1863f66b8e0f2b16ef61d553baabdbe38f56a86.zip | |
Merge pull request #12238 from 0rir/work
327
| -rw-r--r-- | challenge-327/0rir/raku/ch-1.raku | 56 | ||||
| -rw-r--r-- | challenge-327/0rir/raku/ch-2.raku | 48 |
2 files changed, 104 insertions, 0 deletions
diff --git a/challenge-327/0rir/raku/ch-1.raku b/challenge-327/0rir/raku/ch-1.raku new file mode 100644 index 0000000000..bd465bbb36 --- /dev/null +++ b/challenge-327/0rir/raku/ch-1.raku @@ -0,0 +1,56 @@ +#!/usr/bin/env raku +# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ « » ∴ +use v6.d; +use Test; + +=begin comment +Task 1: Missing Integers +Submitted by: Mohammad Sajid Anwar +You are given an array of n integers. + +Write a script to find all the missing integers in the range 1..n in the given array. + + +Example 1 +Input: @ints = (1, 2, 1, 3, 2, 5) +Output: (4, 6) + +The given array has 6 elements. +So we are looking for integers in the range 1..6 in the given array. +The missing integers: (4, 6) + +Example 2 +Input: @ints = (1, 1, 1) +Output: (2, 3) + +Example 3 +Input: @ints = (2, 2, 1) +Output: (3) +=end comment + +my @Test = + [1, 2, 1, 3, 2, 5], (4, 6), + [1, 1, 1], (2, 3), + [2, 2, 1], (3,), + [-1, 0, 100], (1,2,3), + [-1, 0, 100, 1], (2,3,4), + [5,], (1,), +; +my @Die = [], (); + +plan +@Die +@Test ÷ 2; + +# returns an unordered Seq +sub task( @a where *.elems > 0 --> Seq ) { ( (1...+@a) ∖ @a ).keys } + +for @Test -> @in, @exp { + is task( @in).sort, @exp, "{@exp // @exp.^name()} <- @in.raku()"; +} +for @Die -> @in { + dies-ok { task @in }, 'Deader'; +} +done-testing; + +my @int = 1, 2, 1, 3, 2, 5; + +say qq{\nInput: @int = @int.raku()\nOutput: }, task @int; diff --git a/challenge-327/0rir/raku/ch-2.raku b/challenge-327/0rir/raku/ch-2.raku new file mode 100644 index 0000000000..e690ae9170 --- /dev/null +++ b/challenge-327/0rir/raku/ch-2.raku @@ -0,0 +1,48 @@ +#!/usr/bin/env raku +# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ « » ∴ +use v6.d; +use Test; + +=begin comment +327-2: MAD Submitted by: Mohammad Sajid Anwar +You are given an array of distinct integers. + +Write a script to find all pairs of elements with minimum absolute difference (MAD) of any two elements. + +Example 1 +Input: @ints = (4, 1, 2, 3) +Output: [1,2], [2,3], [3,4] + +The minimum absolute difference is 1. +Pairs with MAD: [1,2], [2,3], [3,4] + +Example 2 +Input: @ints = (1, 3, 7, 11, 15) +Output: [1,3] + +Example 3 +Input: @ints = (1, 5, 3, 8) +Output: [1,3], [3,5] +=end comment + +my @Test = + (4, 1, 2, 3), [[1,2], [2,3], [3,4]], + (1, 3, 7, 11, 15), [[1,3],], + (1, 5, 3, 8), [[1,3], [3,5]], +; +plan +@Test ÷ 2; + +multi task( @a is copy where *.elems > 1 ) { + @a = @a.sort.rotor( 2=> -1)».Array; + @a = @a[ (@a.map( { $_[1] - $_[0] }) ).min( :k)]; + +} + +for @Test -> @in, @exp { + is task( @in).raku, @exp.raku, "{@exp // @exp.^name()} <- @in.raku()"; +} +done-testing; + +my @int = 1, 5, 3, 8, 15, 19, 21, 23, -48, -70, -50, -46, 25, 13; + +say qq{\nInput: @int = @int.raku()\nOutput: }, task @int; |
