From ac1ebe39431a887d9d8d3f64ce7fc204d516bdfc Mon Sep 17 00:00:00 2001 From: robbie-hatley Date: Thu, 26 Sep 2024 17:52:24 -0700 Subject: Simplified block merging in 288-2. --- challenge-288/robbie-hatley/perl/ch-2.pl | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'challenge-288') diff --git a/challenge-288/robbie-hatley/perl/ch-2.pl b/challenge-288/robbie-hatley/perl/ch-2.pl index af145b8a63..2159834b6e 100755 --- a/challenge-288/robbie-hatley/perl/ch-2.pl +++ b/challenge-288/robbie-hatley/perl/ch-2.pl @@ -152,12 +152,9 @@ sub max_contiguous_block_size ($mref) { # If we get to here, current AND neighbor already have block numbers. # If they're the same, take no action: next if $ids{$ne} == $ids{$id}; - # Otherwise, assign the lesser block number to all cells with the greater block number: - my ($l, $g); - if ($ids{$id}<$ids{$ne}) {$l = $ids{$id}; $g = $ids{$ne};} - if ($ids{$id}>$ids{$ne}) {$g = $ids{$id}; $l = $ids{$ne};} + # Otherwise, assign the neighbor's block number to all cells with the current block number: for my $key (keys %ids) { - if ($ids{$key} == $g) {$ids{$key} = $l;} + if ($ids{$key} == $ids{$id}) {$ids{$key} = $ids{$ne};} } } } -- cgit