From b289cf381bdb10e895dd261ffde4f25620ef369a Mon Sep 17 00:00:00 2001 From: Andrew Shitov Date: Mon, 25 Mar 2024 14:53:05 +0100 Subject: Solutions in Raku by ash, week 262 --- challenge-262/ash/raku/ch-1.raku | 17 +++++++++++++++++ challenge-262/ash/raku/ch-2.raku | 22 ++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 challenge-262/ash/raku/ch-1.raku create mode 100644 challenge-262/ash/raku/ch-2.raku (limited to 'challenge-262') 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; -- cgit