diff options
| author | Mark <53903062+andemark@users.noreply.github.com> | 2024-02-21 07:22:34 +0000 |
|---|---|---|
| committer | Mark <53903062+andemark@users.noreply.github.com> | 2024-02-21 07:22:34 +0000 |
| commit | ceebdb5c47989c30dcdc24af8262ea983380099b (patch) | |
| tree | 7ebd8c3e24417893700dfe14ccf632fe6252df20 | |
| parent | 2679fd231a01aa21d2b142862819fd69bcf609c4 (diff) | |
| download | perlweeklychallenge-club-ceebdb5c47989c30dcdc24af8262ea983380099b.tar.gz perlweeklychallenge-club-ceebdb5c47989c30dcdc24af8262ea983380099b.tar.bz2 perlweeklychallenge-club-ceebdb5c47989c30dcdc24af8262ea983380099b.zip | |
Challenge 257 Solutions (Raku)
| -rw-r--r-- | challenge-257/mark-anderson/raku/ch-2.raku | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/challenge-257/mark-anderson/raku/ch-2.raku b/challenge-257/mark-anderson/raku/ch-2.raku index 2c53b67dae..abcda264a2 100644 --- a/challenge-257/mark-anderson/raku/ch-2.raku +++ b/challenge-257/mark-anderson/raku/ch-2.raku @@ -37,6 +37,12 @@ nok reduced-row-echelon([1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 0, 0]); +nok reduced-row-echelon([1, 0, 0, 0], + [0, 1, 0, 1], + [0, 0, 1, 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], @@ -73,9 +79,10 @@ sub reduced-row-echelon(+@m) # pivots go from top-left to bottom-right return False unless [<] @cols; - # transpose @m but skip rows and columns that are all zeroes - @m = [Z] @m[^@pivots;@cols].batch(@cols.elems); - - # columns are all zeroes and a 1 - return all @m.map({ all(.sum == 1, .sort ~~ (0,1)) given .Bag.keys.cache }) + # remove extraneous rows and columns + @m = @m[^@pivots;@cols].batch(@cols.elems); + + # @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) }) } |
