aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Anderson <mark@andemark.io>2025-09-06 15:31:54 +0000
committerMark Anderson <mark@andemark.io>2025-09-06 15:31:54 +0000
commitf50ffb1a98bde0e7a0e9cecf9c99bd92302e30c2 (patch)
tree166dd4ba62dc0297891d56bdba7c0836ed539423
parente27044230c74d7769afbb6423d15a2c37c787e9b (diff)
downloadperlweeklychallenge-club-f50ffb1a98bde0e7a0e9cecf9c99bd92302e30c2.tar.gz
perlweeklychallenge-club-f50ffb1a98bde0e7a0e9cecf9c99bd92302e30c2.tar.bz2
perlweeklychallenge-club-f50ffb1a98bde0e7a0e9cecf9c99bd92302e30c2.zip
Updated
-rw-r--r--challenge-337/mark-anderson/raku/ch-1.raku29
-rw-r--r--challenge-337/mark-anderson/raku/ch-2.raku8
2 files changed, 33 insertions, 4 deletions
diff --git a/challenge-337/mark-anderson/raku/ch-1.raku b/challenge-337/mark-anderson/raku/ch-1.raku
index 087445c1c1..1c853a29d3 100644
--- a/challenge-337/mark-anderson/raku/ch-1.raku
+++ b/challenge-337/mark-anderson/raku/ch-1.raku
@@ -1,6 +1,10 @@
#!/usr/bin/env raku
use Test;
+=begin early-bird
+
+# Solution from the original early bird club problem
+
is-deeply stc(6,5,4,8), (2,1,0,3);
is-deeply stc(7,7,7,7), (0,0,0,0);
is-deeply stc(5,4,3,2,1), (4,3,2,1,0);
@@ -14,3 +18,28 @@ sub stc(+@nums)
my %map is Map = @keys Z=> [\+] 0, |%bag{@keys};
%map{@nums}
}
+
+=end early-bird
+
+is-deeply stc([6,5,4,8]), (2,1,0,3);
+is-deeply stc([7,7,7,7]), (3,3,3,3);
+is-deeply stc([5,4,3,2,1]), (4,3,2,1,0);
+is-deeply stc([-1,0,3,-2,1]), (1,2,4,0,3);
+is-deeply stc([0,1,1,2,0]), (1,3,3,4,1);
+
+# 500 numbers
+my @a = (0..99,300..399,500..599,700..799,900..999).flat;
+
+# 1,000,000 random numbers from the above list
+@a .= roll(1e6);
+
+# ~ 1.2 seconds on my computer
+stc(@a);
+
+sub stc(@nums)
+{
+ my %bag is Bag = @nums;
+ my @keys = %bag.keys.sort;
+ my %map is Map = @keys Z=> ([\+] %bag{@keys}) >>->> 1;
+ %map{@nums}
+}
diff --git a/challenge-337/mark-anderson/raku/ch-2.raku b/challenge-337/mark-anderson/raku/ch-2.raku
index f67ef8893f..354df46ff5 100644
--- a/challenge-337/mark-anderson/raku/ch-2.raku
+++ b/challenge-337/mark-anderson/raku/ch-2.raku
@@ -7,10 +7,10 @@ is odd-matrix(3,3,[[0,0],[1,2],[2,1]]), 0;
is odd-matrix(1,5,[[0,2],[0,4]]), 2;
is odd-matrix(4,2,[[1,0],[3,1],[2,0],[0,1]]), 8;
-sub odd-matrix($rows, $cols, @locations)
+sub odd-matrix($rows, $cols, @locs)
{
- my @m = (0 xx $cols).Array xx $rows;
- @m[@locations>>[0];*]>>++;
- @m[*;@locations>>[1]]>>++;
+ my @m = [0 xx $cols] xx $rows;
+ @m[@locs>>[0];*]>>++;
+ @m[*;@locs>>[1]]>>++;
@m[*;*].grep(*.ends-with(any 1,3,5,7,9)).elems
}