From 655c42c9a5fc5f5de4a46108a7bc70e9ecedc930 Mon Sep 17 00:00:00 2001 From: robbie-hatley Date: Tue, 18 Jul 2023 13:02:22 -0700 Subject: Dramatically improved 226-2 --- challenge-226/robbie-hatley/perl/ch-2.pl | 12 +++++++++--- 1 file 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: -- cgit