diff options
| -rwxr-xr-x | challenge-081/dave-jacoby/perl/ch-1.pl | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/challenge-081/dave-jacoby/perl/ch-1.pl b/challenge-081/dave-jacoby/perl/ch-1.pl index 3a753f09e8..44dccb6c91 100755 --- a/challenge-081/dave-jacoby/perl/ch-1.pl +++ b/challenge-081/dave-jacoby/perl/ch-1.pl @@ -36,14 +36,18 @@ sub common_base ( @words ) { my %output; for my $i ( 0 .. length $aa ) { - for my $j ( $i + 1 .. length $aa ) { + for my $j ( 1 .. ( length $aa ) - $i ) { my $aaa = $aa; my $bbb = $bb; my $sub = substr( $aa, $i, $j ); + my $pad = ' ' x $i; $aaa =~ s/$sub//gmix; $bbb =~ s/$sub//gmix; + next unless $aaa eq '' && $bbb eq ''; + # say qq{ $pad$sub\t$aaa\t$bbb}; $output{$sub} = 1 if $aaa eq '' && $bbb eq ''; } + } say join ', ', keys %output; } |
