aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Proctor <simon.proctor@zoopla.co.uk>2020-04-14 09:30:50 +0100
committerSimon Proctor <simon.proctor@zoopla.co.uk>2020-04-14 09:30:50 +0100
commitf9af7643c2d12b53f0f8a11ed189c38e739dda00 (patch)
tree4353e9f27301782f55c0937577577f02dc5d5163
parentbe77a44d43b8fd53557827d6bc6ce0101d05d558 (diff)
downloadperlweeklychallenge-club-f9af7643c2d12b53f0f8a11ed189c38e739dda00.tar.gz
perlweeklychallenge-club-f9af7643c2d12b53f0f8a11ed189c38e739dda00.tar.bz2
perlweeklychallenge-club-f9af7643c2d12b53f0f8a11ed189c38e739dda00.zip
Challenge 1
-rw-r--r--challenge-056/simon-proctor/raku/ch-1.p625
1 files changed, 25 insertions, 0 deletions
diff --git a/challenge-056/simon-proctor/raku/ch-1.p6 b/challenge-056/simon-proctor/raku/ch-1.p6
new file mode 100644
index 0000000000..345bb36449
--- /dev/null
+++ b/challenge-056/simon-proctor/raku/ch-1.p6
@@ -0,0 +1,25 @@
+#!/usr/bin/env raku
+
+use v6;
+
+#| Given a list of positive integers take the first a k and finds the indicies i,j in the list
+#| where @N[i] - @N[j] == k
+sub MAIN ( UInt $k, *@N where { $_.all ~~ UInt && $_.elems >= 2 } ) {
+ # Sort the list
+ @N = @N.sort( { $^a <=> $^b } );
+ say "Given the list {@N} and target $k";
+ LOOP:
+ for @N.keys -> $i {
+ for $i..(@N.end) -> $j {
+ next if $i ~~ $j;
+ given @N[$j] - @N[$i] {
+ when $k {
+ say "$j, $i => {@N[$j]} - {@N[$i]} = $k";
+ }
+ when * > $k {
+ next LOOP;
+ }
+ }
+ }
+ }
+}