diff options
| author | BarrOff <58253563+BarrOff@users.noreply.github.com> | 2025-06-29 22:57:52 +0200 |
|---|---|---|
| committer | BarrOff <58253563+BarrOff@users.noreply.github.com> | 2025-06-29 22:57:52 +0200 |
| commit | a3a25d4a6371e61085f89250ba27cea6a2fd95ea (patch) | |
| tree | ba8ff3d76927fad31a907594240c018fc3d77d83 | |
| parent | 3495f39a1245ae75e4aa8c3862186211a5b33a5b (diff) | |
| download | perlweeklychallenge-club-a3a25d4a6371e61085f89250ba27cea6a2fd95ea.tar.gz perlweeklychallenge-club-a3a25d4a6371e61085f89250ba27cea6a2fd95ea.tar.bz2 perlweeklychallenge-club-a3a25d4a6371e61085f89250ba27cea6a2fd95ea.zip | |
feat: add solutions for challenge 327 from BarrOff
| -rw-r--r-- | challenge-327/barroff/raku/ch-1.p6 | 22 | ||||
| -rw-r--r-- | challenge-327/barroff/raku/ch-2.p6 | 30 |
2 files changed, 52 insertions, 0 deletions
diff --git a/challenge-327/barroff/raku/ch-1.p6 b/challenge-327/barroff/raku/ch-1.p6 new file mode 100644 index 0000000000..a17ac5296f --- /dev/null +++ b/challenge-327/barroff/raku/ch-1.p6 @@ -0,0 +1,22 @@ +#!/usr/bin/env raku + +use v6.d; + +sub missing-integers(@ints --> Positional) { + Set(1..@ints.elems) (-) Set(@ints).keys.List +} + +#| Run test cases +multi sub MAIN('test') { + use Test; + plan 3; + + is missing-integers([1, 2, 1, 3, 2, 5]).sort, (4, 6), 'works for "[1, 2, 1, 3, 2, 5]"'; + is missing-integers([1, 1, 1]).sort, (2, 3), 'works for "[1, 1, 1]"'; + is missing-integers([2, 2, 1]), (3), 'works for "[2, 2, 1]"'; +} + +#| Take user provided numbers like 3, 30, 34, 5, 9 +multi sub MAIN(*@ints) { + say missing-integers(@ints); +} diff --git a/challenge-327/barroff/raku/ch-2.p6 b/challenge-327/barroff/raku/ch-2.p6 new file mode 100644 index 0000000000..fbfe056d05 --- /dev/null +++ b/challenge-327/barroff/raku/ch-2.p6 @@ -0,0 +1,30 @@ +#!/usr/bin/env raku + +use v6.d; + +sub mad(@ints where @ints.elems == @ints.unique.elems --> Array) { + my %differences; + + map({ %differences{abs(@_[0] - @_[1])}.push(@_.sort) }, @ints.combinations: 2); + return %differences{ + min( + %differences.keys, + :by({ Int($_) }) + ) + }; +} + +#| Run test cases +multi sub MAIN('test') { + use Test; + plan 3; + + is sort(mad([4, 1, 2, 3])), [[1, 2], [2, 3], [3, 4]], 'works for "[4, 1, 2, 3]"'; + is sort(mad([1, 3, 7, 11, 15])), [[1, 3]], 'works for "[1, 3, 7, 11, 15]"'; + is sort(mad([1, 5, 3, 8])), [[1, 3], [3, 5]], 'works for "[1, 5, 3, 8]"'; +} + +#| Take user provided numbers like 1 2 3 4 +multi sub MAIN(*@ints) { + say mad(@ints); +} |
