diff options
| -rw-r--r-- | challenge-088/simon-proctor/raku/ch-1.raku | 32 |
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; +} + |
