aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-244/0rir/raku/ch-1.raku74
-rw-r--r--challenge-244/0rir/raku/ch-2.raku56
2 files changed, 130 insertions, 0 deletions
diff --git a/challenge-244/0rir/raku/ch-1.raku b/challenge-244/0rir/raku/ch-1.raku
new file mode 100644
index 0000000000..31e4c8b874
--- /dev/null
+++ b/challenge-244/0rir/raku/ch-1.raku
@@ -0,0 +1,74 @@
+#!/usr/bin/env raku
+# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉ ≡ ≢ «␤ » ∴
+use v6.d;
+use lib $?FILE.IO.cleanup.parent(2).add("lib");
+use Test;
+
+
+=begin comment
+244-1: Count Smaller Submitted by: Mohammad S Anwar
+Given an array of integers, write a script to calculate the number of
+integers smaller than the integer at each index.
+
+Example 1
+Input: @int = (8, 1, 2, 2, 3)
+Output: (4, 0, 1, 1, 3)
+
+For index = 0, count of elements less 8 is 4.
+For index = 1, count of elements less 1 is 0.
+For index = 2, count of elements less 2 is 1.
+For index = 3, count of elements less 2 is 1.
+For index = 4, count of elements less 3 is 3.
+Example 2
+Input: @int = (6, 5, 4, 8)
+Output: (2, 1, 0, 3)
+Example 3
+Input: @int = (2, 2, 2)
+Output: (0, 0, 0)
+Task 1: Count Smaller
+Submitted by: Mohammad S Anwar
+You are given an array of integers.
+
+Write a script to calculate the number of integers smaller than the integer at each index.
+
+Example 1
+Input: @int = (8, 1, 2, 2, 3)
+Output: (4, 0, 1, 1, 3)
+
+For index = 0, count of elements less 8 is 4.
+For index = 1, count of elements less 1 is 0.
+For index = 2, count of elements less 2 is 1.
+For index = 3, count of elements less 2 is 1.
+For index = 4, count of elements less 3 is 3.
+Example 2
+Input: @int = (6, 5, 4, 8)
+Output: (2, 1, 0, 3)
+Example 3
+Input: @int = (2, 2, 2)
+Output: (0, 0, 0)
+
+=end comment
+
+my @Test =
+ # in exp
+ (8, 1, 2, 2, 3), (4, 0, 1, 1, 3),
+ (6, 5, 4, 8), (2, 1, 0, 3),
+ (2, 2, 2), (0, 0, 0),
+;
+plan @Test ÷ 2;
+
+sub func( @a --> Array) {
+ @a.map( { @a.grep( * < $_).Int}).Array;
+}
+
+for @Test -> @in, @exp {
+ is func(@in), @exp, "@in.raku() -> @@exp.raku()";
+}
+done-testing;
+
+my @int = 1,2,7,9,4,0,-1;
+
+say "\nInput: @int = @int[]\nOutput: ", func @int;
+
+exit;
+
diff --git a/challenge-244/0rir/raku/ch-2.raku b/challenge-244/0rir/raku/ch-2.raku
new file mode 100644
index 0000000000..081a55bf41
--- /dev/null
+++ b/challenge-244/0rir/raku/ch-2.raku
@@ -0,0 +1,56 @@
+#!/usr/bin/env raku
+# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉ ≡ ≢ «␤ » ∴
+use v6.d;
+use lib $?FILE.IO.cleanup.parent(2).add("lib");
+use Test;
+
+
+=begin comment
+244 2: Group Hero Submitted by: Mohammad S Anwar
+You are given an array of integers representing the strength.
+Write a script to return the sum of the powers of all possible combinations; power is defined as the square of the largest number in a sequence, multiplied by the smallest.
+
+
+Example 1
+Input: @nums = (2, 1, 4)
+Output: 141
+
+Group 1: (2) => square(max(2)) * min(2) => 4 * 2 => 8
+Group 2: (1) => square(max(1)) * min(1) => 1 * 1 => 1
+Group 3: (4) => square(max(4)) * min(4) => 16 * 4 => 64
+Group 4: (2,1) => square(max(2,1)) * min(2,1) => 4 * 1 => 4
+Group 5: (2,4) => square(max(2,4)) * min(2,4) => 16 * 2 => 32
+Group 6: (1,4) => square(max(1,4)) * min(1,4) => 16 * 1 => 16
+Group 7: (2,1,4) => square(max(2,1,4)) * min(2,1,4) => 16 * 1 => 16
+
+Sum: 8 + 1 + 64 + 4 + 32 + 16 + 16 => 141
+
+=end comment
+
+my @Test =
+ # in exp
+ (0,), 0,
+ (1,), 1,
+ (1,0), 1,
+ (-10, -1, 5), -1411,
+ (2, 0, 1, -10), -1167,
+ (2, 1, 4), 141,
+ (2,2,2,2), 120,
+;
+
+plan @Test ÷ 2;
+
+sub func( @a where *.end > -1) {
+ [+] @a.combinations( 1..@a).map: { .min × .max² } ; # do-able w/ Whatever?
+}
+
+for @Test -> @in, $exp {
+ is func(@in), $exp, "$exp <= @in[]";
+}
+
+done-testing;
+
+my @num = 2, 0, 1, -10;
+say "\nInput: @num = @num[]\nOutput: ", func( @num).raku;
+exit;
+