diff options
| author | Andrew Shitov <mail@andreyshitov.com> | 2024-03-25 14:53:05 +0100 |
|---|---|---|
| committer | Andrew Shitov <mail@andreyshitov.com> | 2024-03-25 14:53:05 +0100 |
| commit | b289cf381bdb10e895dd261ffde4f25620ef369a (patch) | |
| tree | 533d21ca34d8384c1492093662ac00864c0dc75c /challenge-262/ash | |
| parent | 041fe9129e3ef4d86df461a0feeee1b3740d5758 (diff) | |
| download | perlweeklychallenge-club-b289cf381bdb10e895dd261ffde4f25620ef369a.tar.gz perlweeklychallenge-club-b289cf381bdb10e895dd261ffde4f25620ef369a.tar.bz2 perlweeklychallenge-club-b289cf381bdb10e895dd261ffde4f25620ef369a.zip | |
Solutions in Raku by ash, week 262
Diffstat (limited to 'challenge-262/ash')
| -rw-r--r-- | challenge-262/ash/raku/ch-1.raku | 17 | ||||
| -rw-r--r-- | challenge-262/ash/raku/ch-2.raku | 22 |
2 files changed, 39 insertions, 0 deletions
diff --git a/challenge-262/ash/raku/ch-1.raku b/challenge-262/ash/raku/ch-1.raku new file mode 100644 index 0000000000..11384d5c76 --- /dev/null +++ b/challenge-262/ash/raku/ch-1.raku @@ -0,0 +1,17 @@ +# Solution to Task 1 of The Weekly Challenge 262 +# https://theweeklychallenge.org/blog/perl-weekly-challenge-262/#TASK1 + +# Test run: +# $ raku ch-1.raku +# 4 +# 3 +# 2 + +my @tests = + (-3, 1, 2, -1, 3, -2, 4), + (-1, -2, -3, 1), + (1, 2); + +for @tests -> @test { + say max((@test.grep: * > 0).elems, (@test.grep: * < 0).elems); +} diff --git a/challenge-262/ash/raku/ch-2.raku b/challenge-262/ash/raku/ch-2.raku new file mode 100644 index 0000000000..c63affbede --- /dev/null +++ b/challenge-262/ash/raku/ch-2.raku @@ -0,0 +1,22 @@ +# Solution to Task 2 of The Weekly Challenge 262 +# https://theweeklychallenge.org/blog/perl-weekly-challenge-262/#TASK2 + +# Test run: +# $ raku ch-2.raku +# 4 + +my @ints = 3, 1, 2, 2, 2, 1, 3; +my $k = 2; + +# my @ints = 1, 2, 3; +# my $k = 1; + +my $count = 0; +for ^@ints -> $j { + for ^$j -> $i { + next unless @ints[$i] == @ints[$j]; + $count++ if ($j * $i) %% $k; + } +} + +say $count; |
