diff options
| author | rir <rirans@comcast.net> | 2025-05-07 00:54:31 -0400 |
|---|---|---|
| committer | rir <rirans@comcast.net> | 2025-05-12 09:33:34 -0400 |
| commit | 00774e0d31225a7dbea842734fa2443443784e5f (patch) | |
| tree | 86a1c1f9e3f304bfdb746b49327122cd658d5b59 | |
| parent | 62f1ccaddfc5a65501df9cfdf528d28927fef410 (diff) | |
| download | perlweeklychallenge-club-00774e0d31225a7dbea842734fa2443443784e5f.tar.gz perlweeklychallenge-club-00774e0d31225a7dbea842734fa2443443784e5f.tar.bz2 perlweeklychallenge-club-00774e0d31225a7dbea842734fa2443443784e5f.zip | |
320
| -rw-r--r-- | challenge-320/0rir/raku/ch-1.raku | 40 | ||||
| -rw-r--r-- | challenge-320/0rir/raku/ch-2.raku | 38 |
2 files changed, 78 insertions, 0 deletions
diff --git a/challenge-320/0rir/raku/ch-1.raku b/challenge-320/0rir/raku/ch-1.raku new file mode 100644 index 0000000000..c8fc36a119 --- /dev/null +++ b/challenge-320/0rir/raku/ch-1.raku @@ -0,0 +1,40 @@ +#!/usr/bin/env raku +# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ « » ∴ +use v6.d; +use Test; + +=begin comment +320-Task 1: Maximum Count Submitted by: Mohammad Sajid Anwar +You are given an array of integers. + +Write a script to return the maximum between the number of positive and negative integers. Zero is neither positive nor negative. + + +Example 1 +Input: @ints = (-3, -2, -1, 1, 2, 3) +Output: 3 + +… +=end comment + +my @Test = + # in exp + (-3, -2, -1, 1, 2, 3), 3, + (-2, -1, 0, 0, 1), 2, + (1, 2, 3, 4), 4, + (0,0), 0, + (9,), 1, + (-9,), 1, +; +plan @Test ÷ 2; + +sub task( @a) { max +@a.grep( * > 0), +@a.grep( * < 0) } + +for @Test -> @in, $exp { + is task( @in), $exp, "{$exp // $exp.^name()} <- @in.raku()"; +} +done-testing; + +my @int = -3, -2, -1, 1, 2, 3; + +say qq{\nInput: @int = @int.raku()\nOutput: }, task @int; diff --git a/challenge-320/0rir/raku/ch-2.raku b/challenge-320/0rir/raku/ch-2.raku new file mode 100644 index 0000000000..e8d6f180c4 --- /dev/null +++ b/challenge-320/0rir/raku/ch-2.raku @@ -0,0 +1,38 @@ +#!/usr/bin/env raku +# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ « » ∴ +use v6.d; +use Test; + +=begin comment +320-2: Sum Difference Submitted by: Mohammad Sajid Anwar +You are given an array of positive integers. + +Write a script to return the absolute difference between digit sum and element sum of the given array. + +Example 1 +Input: @ints = (1, 23, 4, 5) +Output: 18 +… +=end comment + +my @Test = + # in exp + (1, 23, 4, 5), 18, + (1, 2, 3, 4, 5), 0, + (1, 2, 34), 27, + (), 0, + (12,), 9, +; + +plan @Test ÷ 2; + +sub task( @a) { ( @a.sum - @a.join.comb.sum ).abs } + +for @Test -> @in, $exp { + is task( @in), $exp, "{$exp // $exp.^name()} <- @in.raku()"; +} +done-testing; + +my @int = 1, 23, 4, 5; + +say qq{\nInput: @int = @int.raku()\nOutput: }, task( @int); |
