aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorE. Choroba <choroba@matfyz.cz>2024-06-04 22:59:57 +0200
committerE. Choroba <choroba@matfyz.cz>2024-06-04 22:59:57 +0200
commit51127394959d72e4f5f16c1d16cc1d283445e793 (patch)
treef7039133b5fe4f816d20c607fe26e0eafd24b61f
parent7aeb2014a04d815bc006a3c337b73426a10ea591 (diff)
downloadperlweeklychallenge-club-51127394959d72e4f5f16c1d16cc1d283445e793.tar.gz
perlweeklychallenge-club-51127394959d72e4f5f16c1d16cc1d283445e793.tar.bz2
perlweeklychallenge-club-51127394959d72e4f5f16c1d16cc1d283445e793.zip
Further optimise 270/2, link to a blog post
-rw-r--r--challenge-270/e-choroba/blog.txt1
-rwxr-xr-xchallenge-270/e-choroba/perl/ch-2.pl14
2 files changed, 6 insertions, 9 deletions
diff --git a/challenge-270/e-choroba/blog.txt b/challenge-270/e-choroba/blog.txt
new file mode 100644
index 0000000000..9974ab20c8
--- /dev/null
+++ b/challenge-270/e-choroba/blog.txt
@@ -0,0 +1 @@
+https://blogs.perl.org/users/e_choroba/2024/06/equalise-an-array.html
diff --git a/challenge-270/e-choroba/perl/ch-2.pl b/challenge-270/e-choroba/perl/ch-2.pl
index 9396cc80ff..b3f26649d6 100755
--- a/challenge-270/e-choroba/perl/ch-2.pl
+++ b/challenge-270/e-choroba/perl/ch-2.pl
@@ -17,15 +17,11 @@ sub equalize_array($x, $y, $ints) {
push @agenda, [$price + $x, \@e] unless $seen{"@e"}++;
if (@$elements > 2 && 2 * $x > $y) {
- for my $i (1, $#$elements) {
- my @e = sort { $a <=> $b } $elements->[0] + 1,
- $elements->[$i] + 1,
- @$elements[grep $_ != 0
- && $_ != $i,
- 0 .. $#$elements];
-
- push @agenda, [$price + $y, \@e] unless $seen{"@e"}++;
- }
+ my @e = sort { $a <=> $b } $elements->[0] + 1,
+ $elements->[1] + 1,
+ @$elements[2 .. $#$elements];
+
+ push @agenda, [$price + $y, \@e] unless $seen{"@e"}++;
}
@agenda = sort { $a->[0] <=> $b->[0] } @agenda;