aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-320/0rir/raku/ch-1.raku40
-rw-r--r--challenge-320/0rir/raku/ch-2.raku38
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);