aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Mahnke <andreas.mahnke@leuphana.de>2025-08-18 14:17:48 +0200
committerAndreas Mahnke <andreas.mahnke@leuphana.de>2025-08-18 14:17:48 +0200
commitbd7154d608ac663d3c8dccaa3ecb629c2ea9b407 (patch)
tree45679e7b1a7dbf69bc6058de9d38ca2b9212beee
parent6cb5d85d959b95b0073b3c08c82fa0aa6c1b8f81 (diff)
downloadperlweeklychallenge-club-bd7154d608ac663d3c8dccaa3ecb629c2ea9b407.tar.gz
perlweeklychallenge-club-bd7154d608ac663d3c8dccaa3ecb629c2ea9b407.tar.bz2
perlweeklychallenge-club-bd7154d608ac663d3c8dccaa3ecb629c2ea9b407.zip
optimization
-rw-r--r--challenge-335/mahnkong/perl/ch-1.pl4
1 files changed, 2 insertions, 2 deletions
diff --git a/challenge-335/mahnkong/perl/ch-1.pl b/challenge-335/mahnkong/perl/ch-1.pl
index 4a7e42509a..31ee2ef606 100644
--- a/challenge-335/mahnkong/perl/ch-1.pl
+++ b/challenge-335/mahnkong/perl/ch-1.pl
@@ -4,7 +4,7 @@ use feature 'signatures';
use Test::More 'no_plan';
sub run(@words) {
- return undef unless scalar(@words);
+ return undef if scalar(@words) < 2;
my %occurences;
my @result;
@@ -12,7 +12,7 @@ sub run(@words) {
foreach my $c (split //, $words[0]) {
if (! exists($occurences{$c})) {
my $max_occurences_all;
- foreach my $word (@words) {
+ foreach my $word (@words[1 .. $#words]) {
my $occurences = () = $word =~ /$c/gi;
$max_occurences_all = $occurences if (!defined $max_occurences_all || $max_occurences_all > $occurences);
}