diff options
| author | BarrOff <58253563+BarrOff@users.noreply.github.com> | 2024-03-31 22:35:00 +0200 |
|---|---|---|
| committer | BarrOff <58253563+BarrOff@users.noreply.github.com> | 2024-03-31 22:35:00 +0200 |
| commit | 6e567d8a87f3947190a7444990bc91e5debcc87a (patch) | |
| tree | a2846e6ec60bc5054e2ef7ff7efcb69a8ab02ae1 /challenge-262/barroff/raku | |
| parent | fdeee3349654c610d6ed2f4aca69ef8985e3c094 (diff) | |
| download | perlweeklychallenge-club-6e567d8a87f3947190a7444990bc91e5debcc87a.tar.gz perlweeklychallenge-club-6e567d8a87f3947190a7444990bc91e5debcc87a.tar.bz2 perlweeklychallenge-club-6e567d8a87f3947190a7444990bc91e5debcc87a.zip | |
feat: add solutions for challenge 262 from BarrOff
Diffstat (limited to 'challenge-262/barroff/raku')
| -rw-r--r-- | challenge-262/barroff/raku/ch-1.p6 | 23 | ||||
| -rw-r--r-- | challenge-262/barroff/raku/ch-2.p6 | 25 |
2 files changed, 48 insertions, 0 deletions
diff --git a/challenge-262/barroff/raku/ch-1.p6 b/challenge-262/barroff/raku/ch-1.p6 new file mode 100644 index 0000000000..90a0eddd06 --- /dev/null +++ b/challenge-262/barroff/raku/ch-1.p6 @@ -0,0 +1,23 @@ +#!/usr/bin/env raku + +use v6.d; + +sub max-positive-negative(@ints --> Int:D) { + max(grep({ $_ < 0 }, @ints).elems, grep({ $_ > 0 }, @ints).elems) +} + +#| Run test cases +multi sub MAIN('test') { + use Test; + plan 3; + + is max-positive-negative([-3, 1, 2, -1, 3, -2, 4]), 4, + 'works for (-3, 1, 2, -1, 3, -2, 4)'; + is max-positive-negative([-1, -2, -3, 1]), 3, 'works for (-1, -2, -3, 1)'; + is max-positive-negative([1, 2]), 2, 'works for (1, 2)'; +} + +#| Take user provided number like 10 1 111 24 1000 +multi sub MAIN(*@ints) { + say max-positive-negative(@ints); +} diff --git a/challenge-262/barroff/raku/ch-2.p6 b/challenge-262/barroff/raku/ch-2.p6 new file mode 100644 index 0000000000..c17de3b0c5 --- /dev/null +++ b/challenge-262/barroff/raku/ch-2.p6 @@ -0,0 +1,25 @@ +#!/usr/bin/env raku + +use v6.d; + +sub count-equal-divisible(Int:D $k, @ints --> Int:D) { + grep( + { @ints[$_[0]] == @ints[$_[1]] and ($_[0] * $_[1]) mod $k == 0 }, + combinations(0..@ints.elems - 1, 2) + ).elems +} + +#| Run test cases +multi sub MAIN('test') { + use Test; + plan 2; + + is count-equal-divisible(2, [3, 1, 2, 2, 2, 1, 3]), 4, + 'works for 2 and (3, 1, 2, 2, 2, 1, 3)'; + is count-equal-divisible(1, [1,2,3]), 0, 'works for 1 and (1,2,3)'; +} + +#| Take user provided number like 10 1 111 24 1000 +multi sub MAIN(Int:D $k, *@ints) { + say count-equal-divisible($k, @ints); +} |
