diff options
author | Guillermo Ramos | 2019-06-30 15:35:54 +0200 |
---|---|---|
committer | Guillermo Ramos | 2019-06-30 15:36:10 +0200 |
commit | 61d3daa4027caff03630c96910623a75075b244a (patch) | |
tree | c93b1bd86e4f98c3ae6dc47e2be7e1ebdfd3d8c5 /014/ch2.pl | |
parent | fb8cf0eb53b8bd8e525f57df5952ccb0616aad51 (diff) | |
download | perlweekly-61d3daa4027caff03630c96910623a75075b244a.tar.gz |
[014#2] Optimizations
Diffstat (limited to '014/ch2.pl')
-rwxr-xr-x | 014/ch2.pl | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -33,10 +33,12 @@ my $max_len = 0; # Given a word, return whether it can be composed using state abbreviations sub suitable { - $_ =~ s/^\s+|\s+$//g; # Trim + $_ =~ s/\s+$//g; # Trim my $len = length $_; - return 0 if $len % 2 != 0; # Length must be even + + # Discard shorter words or the ones which have odd number of letters + return 0 if $len < $max_len || $len % 2 != 0; # Iterate word in 2-letter chunks checking they are valid abbreviations foreach my $i (0 .. $len/2-1) { |