aboutsummaryrefslogtreecommitdiff
path: root/challenge-210/andinus/README
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2023-03-27 16:49:22 +0100
committerGitHub <noreply@github.com>2023-03-27 16:49:22 +0100
commit9e3e295b48ecd4cd97c2e17f2fa98d5fee18c8da (patch)
tree2cf6a6ef958a72006495ff60e23b5d3f8a20b2f1 /challenge-210/andinus/README
parentf00547cd9eb3f1cd8cd132e2a410b5bd5d2c5b7b (diff)
parent8915a66de2cb2a724aee5e55ddfc15580cfdf1d5 (diff)
downloadperlweeklychallenge-club-9e3e295b48ecd4cd97c2e17f2fa98d5fee18c8da.tar.gz
perlweeklychallenge-club-9e3e295b48ecd4cd97c2e17f2fa98d5fee18c8da.tar.bz2
perlweeklychallenge-club-9e3e295b48ecd4cd97c2e17f2fa98d5fee18c8da.zip
Merge branch 'manwar:master' into master
Diffstat (limited to 'challenge-210/andinus/README')
-rw-r--r--challenge-210/andinus/README69
1 files changed, 69 insertions, 0 deletions
diff --git a/challenge-210/andinus/README b/challenge-210/andinus/README
new file mode 100644
index 0000000000..ad1a4a32fa
--- /dev/null
+++ b/challenge-210/andinus/README
@@ -0,0 +1,69 @@
+ ━━━━━━━━━━━━━━━
+ CHALLENGE 188
+
+ Andinus
+ ━━━━━━━━━━━━━━━
+
+
+ 2022-10-27
+
+
+
+
+
+1 Task 1 - Divisible Pairs
+══════════════════════════
+
+ You are given list of integers @list of size $n and divisor $k.
+
+ Write a script to find out count of pairs in the given list that
+ satisfies the following rules.
+
+ The pair (i, j) is eligible if and only if a) 0 <= i < j < len(list)
+ b) list[i] + list[j] is divisible by k
+
+
+ ┌────
+ │ Example 1
+ │ Input: @list = (4, 5, 1, 6), $k = 2
+ │ Output: 2
+ │
+ │ Example 2
+ │ Input: @list = (1, 2, 3, 4), $k = 2
+ │ Output: 2
+ │
+ │ Example 3
+ │ Input: @list = (1, 3, 4, 5), $k = 3
+ │ Output: 2
+ │
+ │ Example 4
+ │ Input: @list = (5, 1, 2, 3), $k = 4
+ │ Output: 2
+ │
+ │ Example 5
+ │ Input: @list = (7, 2, 4, 5), $k = 4
+ │ Output: 1
+ └────
+
+
+1.1 Raku
+────────
+
+ Go over all combinations of elements as per rules and check if their
+ sum is divisible by divisor.
+
+ ┌────
+ │ unit sub MAIN(
+ │ Int $divisor, *@list is copy where *.elems > 0
+ │ );
+ │ @list = @list>>.Int;
+ │
+ │ my Int $pairs;
+ │ for 0 ... @list.end -> $i {
+ │ for $i ... @list.end -> $j {
+ │ next if $i == $j;
+ │ $pairs++ if (@list[$i] + @list[$j]) %% $divisor;
+ │ }
+ │ }
+ │ put $pairs;
+ └────