diff options
| -rwxr-xr-x | challenge-327/simon-proctor/raku/ch-1.raku | 11 | ||||
| -rwxr-xr-x | challenge-327/simon-proctor/raku/ch-2.raku | 22 |
2 files changed, 33 insertions, 0 deletions
diff --git a/challenge-327/simon-proctor/raku/ch-1.raku b/challenge-327/simon-proctor/raku/ch-1.raku new file mode 100755 index 0000000000..86241d14a9 --- /dev/null +++ b/challenge-327/simon-proctor/raku/ch-1.raku @@ -0,0 +1,11 @@ +#!/usr/bin/env raku + +#|(Given a list of integers find all the +values not in the list from 1..n where +n is the length of the list) +sub MAIN( + *@a where @a.all ~~ UInt #= A list of unsigned integers +) { + my @list = @a.map( *.Int ); + ((1..@list.elems) ∖ @list).keys.sort.say; +} diff --git a/challenge-327/simon-proctor/raku/ch-2.raku b/challenge-327/simon-proctor/raku/ch-2.raku new file mode 100755 index 0000000000..807b068e3a --- /dev/null +++ b/challenge-327/simon-proctor/raku/ch-2.raku @@ -0,0 +1,22 @@ +#!/usr/bin/env raku + +#|(Given a list of integers return +a list of pairs which share the minimum absolute +difference found in the list) +sub MAIN ( + *@a where @a.all ~~ Int && @a.unique.elems == @a.elems # A list of distinct integers +) { + my @ret = []; + my $mad = Inf; + for @a.sort.rotor(2 => -1) -> $pair { + my $diff = $pair[1] - $pair[0]; + if ( $diff < $mad ) { + @ret = []; + $mad = $diff; + } + if ( $diff == $mad ) { + @ret.push($pair); + } + } + @ret.say; +} |
