aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-258/ash/raku/ch-1.raku17
-rw-r--r--challenge-258/ash/raku/ch-2.raku23
2 files changed, 40 insertions, 0 deletions
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.
+}