From dcc00890e8b58bf1064040ea70300192d00e5ea4 Mon Sep 17 00:00:00 2001 From: Myoungjin JEON Date: Mon, 23 Nov 2020 09:53:17 +1100 Subject: [ch-087/jeongoon] ch-2.raku bug fixed --- challenge-087/jeongoon/raku/ch-2.raku | 20 +++++++++++--------- 1 file 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; -- cgit