aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2023-07-18 21:13:43 +0100
committerGitHub <noreply@github.com>2023-07-18 21:13:43 +0100
commitb8ad19540f14ff2c8133f953a7a0941c754bd642 (patch)
tree2ce95aaa0647da2dcb9cfbbb7fa92f8242143010
parentf8ac7f6f686b333d4a0c910ec8a51fa03811809d (diff)
parent655c42c9a5fc5f5de4a46108a7bc70e9ecedc930 (diff)
downloadperlweeklychallenge-club-b8ad19540f14ff2c8133f953a7a0941c754bd642.tar.gz
perlweeklychallenge-club-b8ad19540f14ff2c8133f953a7a0941c754bd642.tar.bz2
perlweeklychallenge-club-b8ad19540f14ff2c8133f953a7a0941c754bd642.zip
Merge pull request #8411 from robbie-hatley/226
Dramatically improved 226-2
-rwxr-xr-xchallenge-226/robbie-hatley/perl/ch-2.pl12
1 files changed, 9 insertions, 3 deletions
diff --git a/challenge-226/robbie-hatley/perl/ch-2.pl b/challenge-226/robbie-hatley/perl/ch-2.pl
index f441edc716..4087e95e89 100755
--- a/challenge-226/robbie-hatley/perl/ch-2.pl
+++ b/challenge-226/robbie-hatley/perl/ch-2.pl
@@ -104,9 +104,15 @@ for my $aref (@arrays) {
say "Moving on to next array.";
next;
}
- my @nums = uniq sort {$a<=>$b} @$aref;
- shift @nums if 0 == $nums[0];
- say "Number of operations required = ", scalar(@nums);
+ my $n = 0;
+ my %h;
+ $h{0} = 'yes';
+ for (@$aref) {
+ next if defined $h{$_};
+ ++$n;
+ $h{$_} = 'yes';
+ }
+ say "Number of operations required = $n";
}
# Determine and print execution time: