From d09dc9eae124b2b0a79e6d63ad26df321bb7dfe1 Mon Sep 17 00:00:00 2001 From: Andrey Shitov Date: Wed, 28 Feb 2024 11:32:19 +0100 Subject: Week 258, solutions by ash in Raku --- challenge-258/ash/raku/ch-1.raku | 17 +++++++++++++++++ challenge-258/ash/raku/ch-2.raku | 23 +++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 challenge-258/ash/raku/ch-1.raku create mode 100644 challenge-258/ash/raku/ch-2.raku diff --git a/challenge-258/ash/raku/ch-1.raku b/challenge-258/ash/raku/ch-1.raku new file mode 100644 index 0000000000..aee233359f --- /dev/null +++ b/challenge-258/ash/raku/ch-1.raku @@ -0,0 +1,17 @@ +# Solution to the Task 1 of the Weekly Challenge #258 +# https://theweeklychallenge.org/blog/perl-weekly-challenge-258/#TASK1 + +# Test run: +# $ raku ch-1.raku +# 3 + +my @ints = 10, 1, 111, 24, 1000; # 3 +# my @ints = 111, 1, 11111; # 0 +# my @ints = 2, 8, 1024, 256; # 1 + +say ( + @ints.grep( + *.chars %% 2 + ) + .elems + ); diff --git a/challenge-258/ash/raku/ch-2.raku b/challenge-258/ash/raku/ch-2.raku new file mode 100644 index 0000000000..b7e4c1dd33 --- /dev/null +++ b/challenge-258/ash/raku/ch-2.raku @@ -0,0 +1,23 @@ +# Solution to the Task 2 of the Weekly Challenge #258 +# https://theweeklychallenge.org/blog/perl-weekly-challenge-258/#TASK2 + +# Test run: +# $ raku ch-2.raku +# 17 + +my @ints = 2, 5, 9, 11, 3; +my $k = 1; # 17 +# my $k = 2; # 11 +# my $k = 0; # 2 + +if $k { + my @indices = ( + (1..*).grep({ + $_.base(2).comb.grep(/1/).elems == $k + }) + )[^@ints]; + say [+](@ints[@indices].grep: *.defined); +} +else { + say @ints[0]; # Otherwise no @indices will be ever filled. +} -- cgit