diff options
| author | Scimon <simon.proctor@gmail.com> | 2025-06-23 09:20:21 +0100 |
|---|---|---|
| committer | Scimon <simon.proctor@gmail.com> | 2025-06-23 09:20:21 +0100 |
| commit | 2cdbccd6a0f4c9a48af6e00dc218e1c26df64435 (patch) | |
| tree | d7b0bea66866fb2b848daae5eadaa4233fccc30f /challenge-327 | |
| parent | 99d8fa43930abb471fac2b94b68c0785619b37fc (diff) | |
| download | perlweeklychallenge-club-2cdbccd6a0f4c9a48af6e00dc218e1c26df64435.tar.gz perlweeklychallenge-club-2cdbccd6a0f4c9a48af6e00dc218e1c26df64435.tar.bz2 perlweeklychallenge-club-2cdbccd6a0f4c9a48af6e00dc218e1c26df64435.zip | |
Challenge 327. Blog will come on Friday. I'll add a link in the README when it's done
Diffstat (limited to 'challenge-327')
| -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; +} |
