diff options
| author | Myoungjin JEON <jeongoon@gmail.com> | 2020-11-23 14:58:07 +1100 |
|---|---|---|
| committer | Myoungjin JEON <jeongoon@gmail.com> | 2020-11-23 14:58:07 +1100 |
| commit | 81613265f79de55e0276865e0edafddf5d9244e7 (patch) | |
| tree | 24e5e8fdcf0b8e695d037d268293d8129aa627ab | |
| parent | 77c84beed78906d0ea68ec0762f127dbf8f61ae5 (diff) | |
| download | perlweeklychallenge-club-81613265f79de55e0276865e0edafddf5d9244e7.tar.gz perlweeklychallenge-club-81613265f79de55e0276865e0edafddf5d9244e7.tar.bz2 perlweeklychallenge-club-81613265f79de55e0276865e0edafddf5d9244e7.zip | |
[ch-087/jeongoon] ch-2.raku: just sligtly better performance
| -rw-r--r-- | challenge-087/jeongoon/raku/ch-2.raku | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/challenge-087/jeongoon/raku/ch-2.raku b/challenge-087/jeongoon/raku/ch-2.raku index 76d6ec90f3..838de696eb 100644 --- a/challenge-087/jeongoon/raku/ch-2.raku +++ b/challenge-087/jeongoon/raku/ch-2.raku @@ -44,30 +44,29 @@ map( -> $ln { next if $ln eq ""; # skip empty line with $ln } ); # confirm input -$*ERR.say(.Array) for @matrix; -$*ERR.say; +#$*ERR.say(.Array) for @matrix; +#$*ERR.say; @matrix andthen .kv.map( -> $ri, $rw { # find all lines which has consecutive element of "1" ## a. find cells has value of 1 - $rw.pairs.grep( { .value eq 1 }, :k ).Slip. - ## b. make combinations from 1 to elems - combinations( 1..* ). # one column is *maybe* okay - # except when the column have - # one row (-> point) - ## c. grep only consecutive points - map( -> $cmb { - $cmb.rotor( 2 => -1 ). - map({ [-] .reverse }). # distance between two points - all == 1 # are all equal to one. - ## d. as ( points array , row index ) - ?? ( $cmb, $ri ) - !! Empty } ).Array.Slip + my @one-indices = $rw.pairs.grep( { .value eq 1 }, :k ); + ## b. make combinations from 1 to elems + ( 1..$rw.elems ). # one column is *maybe* okay + map( -> $n # except when the column have + { # one row (-> point) + @one-indices.rotor( $n => -($n.pred) ).Slip } ). + ## c. grep only consecutive points + map( -> $cmb { + next if 1 != any( # skip if + $cmb.rotor( 2 => -1 ). # distance between two points + map({ [-] .reverse }) ); # are not equal to one + ## d. as ( points array , row index ) + ( $cmb, $ri ) } ).Slip } ). - classify( {.[0].Str}, :as{ .[1] } ). # group by same point or line map( { my ($pts-str, $rows) = $_.kv; my $pts = $pts-str.split(/\s+/)>>.Int.Array; # note: >>.Int required @@ -113,3 +112,4 @@ else { ?? "$cv" !! '▨' )} ).Array.say; } } + |
