diff options
| author | Mark <53903062+andemark@users.noreply.github.com> | 2024-02-20 05:18:36 +0000 |
|---|---|---|
| committer | Mark <53903062+andemark@users.noreply.github.com> | 2024-02-20 05:18:36 +0000 |
| commit | f8e133d0e948b5aff8fb5fb037069dbe0eea3b1e (patch) | |
| tree | 813171f493d4f754e0253f1bce4a0958a95e2272 | |
| parent | b3fed3f1c65f49ae58824e51be4275a2783940b0 (diff) | |
| download | perlweeklychallenge-club-f8e133d0e948b5aff8fb5fb037069dbe0eea3b1e.tar.gz perlweeklychallenge-club-f8e133d0e948b5aff8fb5fb037069dbe0eea3b1e.tar.bz2 perlweeklychallenge-club-f8e133d0e948b5aff8fb5fb037069dbe0eea3b1e.zip | |
Challenge 257 Solutions (Raku)
| -rw-r--r-- | challenge-257/mark-anderson/raku/ch-2.raku | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/challenge-257/mark-anderson/raku/ch-2.raku b/challenge-257/mark-anderson/raku/ch-2.raku index a801671767..6ec5d3307a 100644 --- a/challenge-257/mark-anderson/raku/ch-2.raku +++ b/challenge-257/mark-anderson/raku/ch-2.raku @@ -31,6 +31,12 @@ nok reduced-row-echelon([4, 0, 0, 0], [0, 1, 0, 7], [0, 0, 1,-1]); +nok reduced-row-echelon([1, 0, 0, 0], + [0, 1, 0, 3], + [0, 0, 1,-3], + [0, 0, 0, 1], + [0, 0, 0, 0]); + sub reduced-row-echelon(+@m) { # the first non-zero number in a row is the pivot @@ -42,16 +48,19 @@ sub reduced-row-echelon(+@m) # all 0 rows are grouped at the bottom if $k { - return False unless @pivots[$k..*].all eqv Any; + return False unless all(@pivots[$k..*]) eqv Any; @pivots = @pivots[^$k] } # all pivots == 1 - return False unless so @pivots>>[1].all == 1; + return False unless all(@pivots>>[1]) == 1; # pivots go from top-left to bottom-right return False unless [<] @pivots>>[0]; # pivot columns are all 0 (except for the 1) - return all(([Z] @m[^@pivots])[@pivots>>[0]]>>.sum) == 1 + return all (([Z] @m[^@pivots])[@pivots>>[0]]).map({ + all .sum == 1, + all(.Bag.keys) ~~ 0..1 + }) } |
