diff options
| author | Myoungjin JEON <jeongoon@gmail.com> | 2020-11-23 09:53:17 +1100 |
|---|---|---|
| committer | Myoungjin JEON <jeongoon@gmail.com> | 2020-11-23 09:53:17 +1100 |
| commit | dcc00890e8b58bf1064040ea70300192d00e5ea4 (patch) | |
| tree | 25721c658378c5701c3714f2428c6729eca610a8 | |
| parent | 91686aa73860438d729424da3a9faae701042473 (diff) | |
| download | perlweeklychallenge-club-dcc00890e8b58bf1064040ea70300192d00e5ea4.tar.gz perlweeklychallenge-club-dcc00890e8b58bf1064040ea70300192d00e5ea4.tar.bz2 perlweeklychallenge-club-dcc00890e8b58bf1064040ea70300192d00e5ea4.zip | |
[ch-087/jeongoon] ch-2.raku bug fixed
| -rw-r--r-- | challenge-087/jeongoon/raku/ch-2.raku | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/challenge-087/jeongoon/raku/ch-2.raku b/challenge-087/jeongoon/raku/ch-2.raku index 432ee6750c..76d6ec90f3 100644 --- a/challenge-087/jeongoon/raku/ch-2.raku +++ b/challenge-087/jeongoon/raku/ch-2.raku @@ -67,22 +67,24 @@ $*ERR.say; } ). + 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 next if $pts.elems == 1 == $rows.elems; # skip if point my $found = False; - ($rows.elems ... 1). # try from largest + ($rows.elems ... 1). # try from largest area map( { last if $found; - if $rows.combinations( $_ ).lazy. - rotor( 2 => -1 ).map( { [-] .reverse } ).all == 1 { - $found = True; - ($pts, $rows) - } else { - Empty - } - }).Slip } ) + $rows.rotor( $_ => -($_.pred) ). # check rows are consecutive + map( -> $sub-rows + { last if $found; + if $sub-rows.rotor( 2 => -1 ). + map( { [-] .reverse } ).all == 1 { + $found = True; + ($pts.clone, $sub-rows.clone).Slip + } + } ).cache } ).Slip } ) ==> my @candidates; |
