aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark <53903062+andemark@users.noreply.github.com>2024-02-20 10:10:59 +0000
committerMark <53903062+andemark@users.noreply.github.com>2024-02-20 10:10:59 +0000
commit59ca52f10ee43755c07cc65f75cfec0c60904b22 (patch)
treeab834fbdcb1b575f8f6611defb7700f5d840707e
parentf8e133d0e948b5aff8fb5fb037069dbe0eea3b1e (diff)
downloadperlweeklychallenge-club-59ca52f10ee43755c07cc65f75cfec0c60904b22.tar.gz
perlweeklychallenge-club-59ca52f10ee43755c07cc65f75cfec0c60904b22.tar.bz2
perlweeklychallenge-club-59ca52f10ee43755c07cc65f75cfec0c60904b22.zip
Challenge 257 Solutions (Raku)
-rw-r--r--challenge-257/mark-anderson/raku/ch-2.raku23
1 files changed, 16 insertions, 7 deletions
diff --git a/challenge-257/mark-anderson/raku/ch-2.raku b/challenge-257/mark-anderson/raku/ch-2.raku
index 6ec5d3307a..412ac4cf4b 100644
--- a/challenge-257/mark-anderson/raku/ch-2.raku
+++ b/challenge-257/mark-anderson/raku/ch-2.raku
@@ -37,10 +37,16 @@ nok reduced-row-echelon([1, 0, 0, 0],
[0, 0, 0, 1],
[0, 0, 0, 0]);
+ok reduced-row-echelon([1, 0, 0, 0, 0],
+ [0, 1, 0, 0, 0],
+ [0, 0, 0, 0, 1],
+ [0, 0, 0, 0, 0],
+ [0, 0, 0, 0, 0]);
+
sub reduced-row-echelon(+@m)
{
# the first non-zero number in a row is the pivot
- my @pivots = @m>>.first(*.so, :kv);
+ my @pivots = @m>>.first(*.so, :p);
# the first row that is all zeroes
my $k = @pivots.first(*.not, :k);
@@ -52,15 +58,18 @@ sub reduced-row-echelon(+@m)
@pivots = @pivots[^$k]
}
+ my @keys = @pivots>>.keys>>[0];
+ @pivots = @pivots>>.values>>[0];
+
# all pivots == 1
- return False unless all(@pivots>>[1]) == 1;
+ return False unless all(@pivots) == 1;
# pivots go from top-left to bottom-right
- return False unless [<] @pivots>>[0];
+ return False unless [<] @keys;
# pivot columns are all 0 (except for the 1)
- return all (([Z] @m[^@pivots])[@pivots>>[0]]).map({
- all .sum == 1,
- all(.Bag.keys) ~~ 0..1
- })
+ return all (([Z] @m[^@pivots])[@keys]).map({
+ all .sum == 1,
+ all(.Bag.keys) ~~ 0..1
+ })
}