diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-06-12 13:45:17 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-12 13:45:17 +0100 |
| commit | fef6253897be4d34e281518173f5ad316297d03c (patch) | |
| tree | f2c8dd1d029e2e3897e894fbc3d83ca2291b6cdc | |
| parent | 2b3330bc7c40f557fdacbf78e77d940d03ee6fda (diff) | |
| parent | 8a71ee2f23d2931fef1da5d794757641303086e4 (diff) | |
| download | perlweeklychallenge-club-fef6253897be4d34e281518173f5ad316297d03c.tar.gz perlweeklychallenge-club-fef6253897be4d34e281518173f5ad316297d03c.tar.bz2 perlweeklychallenge-club-fef6253897be4d34e281518173f5ad316297d03c.zip | |
Merge pull request #12168 from 0rir/work
325
| -rw-r--r-- | challenge-323/0rir/raku/ch-2.raku | 2 | ||||
| -rw-r--r-- | challenge-324/0rir/raku/ch-2.raku | 2 | ||||
| -rw-r--r-- | challenge-325/0rir/raku/ch-1.raku | 49 | ||||
| -rw-r--r-- | challenge-325/0rir/raku/ch-2.raku | 51 |
4 files changed, 102 insertions, 2 deletions
diff --git a/challenge-323/0rir/raku/ch-2.raku b/challenge-323/0rir/raku/ch-2.raku index 1c7b7b7636..dd6c696896 100644 --- a/challenge-323/0rir/raku/ch-2.raku +++ b/challenge-323/0rir/raku/ch-2.raku @@ -46,7 +46,7 @@ plan +@Test; enum Bracket< LOWER UPPER RATE TX-BASE TX-IN TX-MAX>; # Cache and stack the brackets so only one bracket need be in tax calculation. -sub create-brackets( @sch -->Tax-schedule) { +sub create-brackets( @sch ) { my $idx = ^@sch; my @ret = @sch.Array.deepmap({$_}); diff --git a/challenge-324/0rir/raku/ch-2.raku b/challenge-324/0rir/raku/ch-2.raku index 918b5d228d..c56d81f5f2 100644 --- a/challenge-324/0rir/raku/ch-2.raku +++ b/challenge-324/0rir/raku/ch-2.raku @@ -51,7 +51,7 @@ my @Test = plan +@Test ÷ 2; sub task( @a where { **.are(Int) or ** ~~ Empty } -->Int:D) { - sum do for @a.combinations { sum [+^] $_ } +sum do for @a.combinations { [+^] $_ } } for @Test -> @in, $exp { diff --git a/challenge-325/0rir/raku/ch-1.raku b/challenge-325/0rir/raku/ch-1.raku new file mode 100644 index 0000000000..77bf38fd1a --- /dev/null +++ b/challenge-325/0rir/raku/ch-1.raku @@ -0,0 +1,49 @@ +#!/usr/bin/env raku +# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ « » ∴ +use v6.d; +use Test; + +=begin comment +Task 1: Consecutive One Submitted by: Mohammad Sajid Anwar + +You are given a binary array containing only 0 or/and 1. +Write a script to find out the maximum consecutive 1 in the given array. + + +Example 1 +Input: @binary = (0, 1, 1, 0, 1, 1, 1) +Output: 3 + +Example 2 +Input: @binary = (0, 0, 0, 0) +Output: 0 + +Example 3 +Input: @binary = (1, 0, 1, 0, 1, 1) +Output: 2 +=end comment + +my @Test = + # in exp + (0, 1, 1, 0, 1, 1, 1), 3, + (0, 0, 0, 0), 0, + (1, 0, 1, 0, 1, 1), 2, + (), 0, +; +plan +@Test ÷ 2; + +sub task( @in) { + $_ = ( ( (@in.join ~~ m:g/1+/)».Str + )».chars + ).max; + $_ == -∞ ?? 0 !! $_ +} + +for @Test -> @in,$exp { + is task( @in), $exp, "{$exp // $exp.^name()} <- @in.raku()"; +} +done-testing; + +my @binary = 1, 0, 1, 0, 1, 1; +say qq{Input: @binary = @binary.raku()\nOutput: }, task @binary; + diff --git a/challenge-325/0rir/raku/ch-2.raku b/challenge-325/0rir/raku/ch-2.raku new file mode 100644 index 0000000000..58fa3f75fb --- /dev/null +++ b/challenge-325/0rir/raku/ch-2.raku @@ -0,0 +1,51 @@ +#!/usr/bin/env raku +# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ « » ∴ +use v6.d; +use Test; + +=begin comment +Task 2: Final Price Submitted by: Mohammad Sajid Anwar +You are given an array of item prices. +Write a script to find out the final price of each items in the given array. + +There is a special discount scheme going on. If there’s an item with a lower or equal price later in the list, you get a discount equal to that later price (the first one you find in order). + +Example 1 +Input: @prices = (8, 4, 6, 2, 3) +Output: (4, 2, 4, 2, 3) + +Example 2 +Input: @prices = (1, 2, 3, 4, 5) +Output: (1, 2, 3, 4, 5) + +Example 3 +Input: @prices = (7, 1, 1, 5) +Output: (6, 0, 1, 5) + +=end comment + +my @Test = + # in exp + (8, 4, 6, 2, 3), (4, 2, 4, 2, 3), + (1, 2, 3, 4, 5), (1,2, 3, 4, 5), + (7, 1, 1, 5), (6, 0, 1, 5), +; +plan +@Test ÷ 2; + +sub task( @l) { + my @a = @l; + for 0..^@a.end -> \i { + @a[i] = @a[i] - (@a[i+1..@a-1].first( * ≤ @a[i]) // 0); + } + @a; +} + +for @Test -> @in, @exp { + is task( @in), @exp, "{@exp // @exp.^name()} <- @in.raku()"; +} +done-testing; + +my @price = 8, 4, 6, 2, 3; + +say "\nInput: @price = @price.raku()\nOutput: {task(@price)}"; + |
