summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-x014/ch2.pl6
1 files changed, 4 insertions, 2 deletions
diff --git a/014/ch2.pl b/014/ch2.pl
index ae9027f..33e3092 100755
--- a/014/ch2.pl
+++ b/014/ch2.pl
@@ -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) {