diff options
| -rw-r--r-- | challenge-325/0rir/raku/ch-1.raku | 49 | ||||
| -rw-r--r-- | challenge-325/0rir/raku/ch-2.raku | 51 |
2 files changed, 100 insertions, 0 deletions
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)}"; + |
