diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-06-20 23:28:13 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-20 23:28:13 +0100 |
| commit | e78a03785ea967d8b02240ffec43a1ab81037f03 (patch) | |
| tree | f6c615737a63443bd642e061ebd203c057acdeb0 | |
| parent | d909b7dadedada08fa9383b744331d5f9e7a54e9 (diff) | |
| parent | 9aa8c2e6a83b3684aa221167be5f79cfb52257e8 (diff) | |
| download | perlweeklychallenge-club-e78a03785ea967d8b02240ffec43a1ab81037f03.tar.gz perlweeklychallenge-club-e78a03785ea967d8b02240ffec43a1ab81037f03.tar.bz2 perlweeklychallenge-club-e78a03785ea967d8b02240ffec43a1ab81037f03.zip | |
Merge pull request #12206 from 0rir/work
326
| -rw-r--r-- | challenge-326/0rir/raku/ch-1.raku | 50 | ||||
| -rw-r--r-- | challenge-326/0rir/raku/ch-2.raku | 57 |
2 files changed, 107 insertions, 0 deletions
diff --git a/challenge-326/0rir/raku/ch-1.raku b/challenge-326/0rir/raku/ch-1.raku new file mode 100644 index 0000000000..63f08d786e --- /dev/null +++ b/challenge-326/0rir/raku/ch-1.raku @@ -0,0 +1,50 @@ +#!/usr/bin/env raku +# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ « » ∴ +use v6.d; +use Test; + +=begin comment +Task 1: Day of the Year +Submitted by: Mohammad Sajid Anwar +You are given a date in the format YYYY-MM-DD. + +Write a script to find day number of the year that the given date represent. + + +Example 1 +Input: $date = '2025-02-02' +Output: 33 + +The 2nd Feb, 2025 is the 33rd day of the year. + +Example 2 +Input: $date = '2025-04-10' +Output: 100 + +Example 3 +Input: $date = '2025-09-07' +Output: 250 + 0, +=end comment + +my @Test = + # in exp + '2025-02-02', 33, + '2025-04-10', 100, + '2025-09-07', 250, +; +plan +@Test ÷ 2; + +sub task( $a) { + $a.Date.day-of-year; +} + +for @Test -> $in, $exp { + is task( $in), $exp, "{$exp // $exp.^name()} <- $in"; +} +done-testing; + +my $date = '2025-09-07'; + +say "\nInput: \$date = '$date'\nOutput: ", task $date.Date; + diff --git a/challenge-326/0rir/raku/ch-2.raku b/challenge-326/0rir/raku/ch-2.raku new file mode 100644 index 0000000000..48babadcdb --- /dev/null +++ b/challenge-326/0rir/raku/ch-2.raku @@ -0,0 +1,57 @@ +#!/usr/bin/env raku +# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ « » ∴ +use v6.d; +use Test; + +=begin comment +Task 2: Decompressed List +Submitted by: Mohammad Sajid Anwar +You are given an array of positive integers having even elements. + +Write a script to to return the decompress list. To decompress, pick adjacent pair (i, j) and replace it with j, i times. + + +Example 1 +Input: @ints = (1, 3, 2, 4) +Output: (3, 4, 4) + +Pair 1: (1, 3) => 3 one time => (3) +Pair 2: (2, 4) => 4 two times => (4, 4) + +Example 2 +Input: @ints = (1, 1, 2, 2) +Output: (1, 2, 2) + +Pair 1: (1, 1) => 1 one time => (1) +Pair 2: (2, 2) => 2 two times => (2, 2) + +Example 3 +Input: @ints = (3, 1, 3, 2) +Output: (1, 1, 1, 2, 2, 2) + +Pair 1: (3, 1) => 1 three times => (1, 1, 1) +Pair 2: (3, 2) => 2 three times => (2, 2, 2) + +=end comment + +my @Test = + # in exp + (1, 3, 2, 4), (3, 4, 4), + (1, 1, 2, 2), (1, 2, 2), + (3, 1, 3, 2), (1, 1, 1, 2, 2, 2), +; +plan +@Test ÷ 2; + +sub task( @a ) { + ( flat do for @a.rotor(2) -> @p { @p[0] Rxx @p[1] } + ).List +} + +for @Test -> @in, @exp, { + is task( @in), @exp, "{@exp // @exp.^name()} <- @in.raku()"; +} +done-testing; + +my @int = (3, 1, 3, 2); +say "\nInput: @int = @int.raku()\nOutput: ", task(@int).raku; + |
