diff options
| author | Dave Jacoby <jacoby.david@gmail.com> | 2020-10-06 19:33:44 -0400 |
|---|---|---|
| committer | Dave Jacoby <jacoby.david@gmail.com> | 2020-10-06 19:33:44 -0400 |
| commit | 2a164009eaff581dc487a5fc955c7421a8ba7a31 (patch) | |
| tree | ca3b6e90309fdde33c59ea8cb850462cf1cccecd | |
| parent | 5a7b6deedb64b69ddad17271be3714f5d0f1334c (diff) | |
| download | perlweeklychallenge-club-2a164009eaff581dc487a5fc955c7421a8ba7a31.tar.gz perlweeklychallenge-club-2a164009eaff581dc487a5fc955c7421a8ba7a31.tar.bz2 perlweeklychallenge-club-2a164009eaff581dc487a5fc955c7421a8ba7a31.zip | |
Better loops
| -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; } |
