aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-09-27 17:11:53 +0100
committerGitHub <noreply@github.com>2024-09-27 17:11:53 +0100
commit7edd323084abf409f31f428ba69b3613b44cac44 (patch)
tree2c9f08f09355a9a5a57cedab04af5dd6fe857563
parente7fe0fc61e221a4f8e5bbb6848cfd81789ebf7a3 (diff)
parente44f889a41225e521919e5e3f941483bd0d259ab (diff)
downloadperlweeklychallenge-club-7edd323084abf409f31f428ba69b3613b44cac44.tar.gz
perlweeklychallenge-club-7edd323084abf409f31f428ba69b3613b44cac44.tar.bz2
perlweeklychallenge-club-7edd323084abf409f31f428ba69b3613b44cac44.zip
Merge pull request #10914 from robbie-hatley/rh288
Simplified block merging in 288-2.
-rwxr-xr-xchallenge-288/robbie-hatley/perl/ch-2.pl10
1 files changed, 4 insertions, 6 deletions
diff --git a/challenge-288/robbie-hatley/perl/ch-2.pl b/challenge-288/robbie-hatley/perl/ch-2.pl
index af145b8a63..4007dff681 100755
--- a/challenge-288/robbie-hatley/perl/ch-2.pl
+++ b/challenge-288/robbie-hatley/perl/ch-2.pl
@@ -152,12 +152,10 @@ 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,
+ # thus merging the two blocks:
for my $key (keys %ids) {
- if ($ids{$key} == $g) {$ids{$key} = $l;}
+ if ($ids{$key} == $ids{$id}) {$ids{$key} = $ids{$ne};}
}
}
}
@@ -200,7 +198,7 @@ my @matrices = @ARGV ? eval($ARGV[0]) :
# ------------------------------------------------------------------------------------------------------------
# MAIN BODY OF PROGRAM:
-$"=', ';
+$"=' ';
for my $mref (@matrices) {
say '';
my @matrix = @$mref;