From f9af7643c2d12b53f0f8a11ed189c38e739dda00 Mon Sep 17 00:00:00 2001 From: Simon Proctor Date: Tue, 14 Apr 2020 09:30:50 +0100 Subject: Challenge 1 --- challenge-056/simon-proctor/raku/ch-1.p6 | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 challenge-056/simon-proctor/raku/ch-1.p6 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; + } + } + } + } +} -- cgit