aboutsummaryrefslogtreecommitdiff
path: root/challenge-257
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-02-21 19:34:24 +0000
committerGitHub <noreply@github.com>2024-02-21 19:34:24 +0000
commitaffe324946efc32a69855b98f806e77f06bd1438 (patch)
treea67b1d5ed09b556f3815133cc45d8d7f0518dee9 /challenge-257
parent2cab60c3897e48af340150e0ec47dff772c0b38c (diff)
parent941a18cfc57a329f18399109c26022f06a0be161 (diff)
downloadperlweeklychallenge-club-affe324946efc32a69855b98f806e77f06bd1438.tar.gz
perlweeklychallenge-club-affe324946efc32a69855b98f806e77f06bd1438.tar.bz2
perlweeklychallenge-club-affe324946efc32a69855b98f806e77f06bd1438.zip
Merge pull request #9625 from andemark/challenge-257
ch-2.raku final (hopefully)
Diffstat (limited to 'challenge-257')
-rw-r--r--challenge-257/mark-anderson/raku/ch-2.raku15
1 files changed, 9 insertions, 6 deletions
diff --git a/challenge-257/mark-anderson/raku/ch-2.raku b/challenge-257/mark-anderson/raku/ch-2.raku
index 5c4c4cf95d..f772c06ebd 100644
--- a/challenge-257/mark-anderson/raku/ch-2.raku
+++ b/challenge-257/mark-anderson/raku/ch-2.raku
@@ -65,7 +65,7 @@ sub reduced-row-echelon(+@m)
# rows with all zeroes are grouped at the bottom
with $k
{
- return False unless all(@pivots[$k..*]) eqv Any;
+ return False unless all(@pivots[$k..*]) ~~ Any;
@pivots = @pivots[^$k];
return True unless @pivots
}
@@ -76,10 +76,13 @@ sub reduced-row-echelon(+@m)
# pivots go from top-left to bottom-right
return False unless [<] @cols;
- # remove extraneous rows and columns
- @m = @m[^@pivots;@cols].batch(@cols.elems);
+ # remove zero rows and non-pivot columns
+ @m = @m[^@pivots;@cols].batch(@cols.elems)>>.Array;
+ # @m should be an identity matrix at this point if it is RREF
- # @m should be an identity matrix at this point
- # so check rows for all zeroes and a 1
- return all @m.map({ all(.sum == 1, all(.Bag.keys) == 0|1) })
+ # all pivots are ones
+ return False unless squish(@m.keys.map({ |@m[$_].splice($_,1) })) ~~ (1,);
+
+ # everything else is zeroes
+ return squish(@m[*;*]) ~~ (0,)
}