aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Proctor <simon.proctor@zoopla.co.uk>2020-11-23 09:21:06 +0000
committerSimon Proctor <simon.proctor@zoopla.co.uk>2020-11-23 09:21:06 +0000
commit9cd5dbe59de0919378066e0bed96d8fdf45b3928 (patch)
tree556e42ab6e9c18f8b5aad3a45022b33264823126
parentcea83925f87e4bbe52ab8c1ce9a2e1b0f2d86611 (diff)
downloadperlweeklychallenge-club-9cd5dbe59de0919378066e0bed96d8fdf45b3928.tar.gz
perlweeklychallenge-club-9cd5dbe59de0919378066e0bed96d8fdf45b3928.tar.bz2
perlweeklychallenge-club-9cd5dbe59de0919378066e0bed96d8fdf45b3928.zip
Challenge 1
-rw-r--r--challenge-088/simon-proctor/raku/ch-1.raku32
1 files changed, 32 insertions, 0 deletions
diff --git a/challenge-088/simon-proctor/raku/ch-1.raku b/challenge-088/simon-proctor/raku/ch-1.raku
new file mode 100644
index 0000000000..0f87839e37
--- /dev/null
+++ b/challenge-088/simon-proctor/raku/ch-1.raku
@@ -0,0 +1,32 @@
+#!/usr/bin/env raku
+
+use v6;
+
+multi sub MAIN(
+ 'ex1' #= Example 1 (5, 2, 1, 4, 3)
+) {
+ product-array( [5,2,1,4,3] ).join(", ").say;
+}
+
+
+multi sub MAIN(
+ 'ex2' #= Example 2 (2, 1, 4, 3)
+) {
+ product-array( [2,1,4,3] ).join(", ").say;
+}
+
+#| Given a list of Integers return the list of products for each item barring the one at the same index
+multi sub MAIN(
+ *@N where { $_.all ~~ Int }
+) {
+ product-array( @N ).join(", ").say;
+}
+
+sub product-array( @N ) {
+ my @M;
+ for @N.keys -> $i {
+ @M[$i] = [*] @N[ @N.keys.grep(!(*~~$i)) ]
+ }
+ @M;
+}
+