diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2019-08-04 00:17:45 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-08-04 00:17:45 +0100 |
| commit | a424711822fadac955b5ae4508650e6fc9224bfe (patch) | |
| tree | 07ba58e5c1ddf104b9ab4389a40844de959df679 | |
| parent | 137fea5ffc970163e0d0e0af37ef3f58fc1a5852 (diff) | |
| parent | c78d67d093595edab30a61e8d7b1e1c7c1dda672 (diff) | |
| download | perlweeklychallenge-club-a424711822fadac955b5ae4508650e6fc9224bfe.tar.gz perlweeklychallenge-club-a424711822fadac955b5ae4508650e6fc9224bfe.tar.bz2 perlweeklychallenge-club-a424711822fadac955b5ae4508650e6fc9224bfe.zip | |
Merge pull request #464 from choroba/ech19u
Improve E. Choroba's solution according to his blog post
| -rw-r--r-- | challenge-019/e-choroba/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-019/e-choroba/perl5/ch-1.pl | 11 | ||||
| -rwxr-xr-x | challenge-019/e-choroba/perl5/ch-2.pl | 4 |
3 files changed, 8 insertions, 8 deletions
diff --git a/challenge-019/e-choroba/blog.txt b/challenge-019/e-choroba/blog.txt new file mode 100644 index 0000000000..60e0749e67 --- /dev/null +++ b/challenge-019/e-choroba/blog.txt @@ -0,0 +1 @@ +http://blogs.perl.org/users/e_choroba/2019/08/perl-weekly-challenge-019-five-weekends-and-paragraph-wrapping.html diff --git a/challenge-019/e-choroba/perl5/ch-1.pl b/challenge-019/e-choroba/perl5/ch-1.pl index f6b0f73fa4..5b436e9287 100755 --- a/challenge-019/e-choroba/perl5/ch-1.pl +++ b/challenge-019/e-choroba/perl5/ch-1.pl @@ -10,9 +10,10 @@ my $date = 'Time::Piece'->strptime( '1900-01-01 12:00:00', '%Y-%m-%d %H:%M:%S'); while ($date->year < 2020) { - $date += ONE_DAY until $date->day eq 'Fri'; - if ($date->mday == 1 && $date->month_last_day == 31) { - say $date->strftime('%Y-%m'); - } - $date += ($date->month_last_day - $date->mday + 1) * ONE_DAY; + next if $date->day ne 'Fri'; + + say $date->strftime('%Y-%m') if $date->month_last_day == 31; + +} continue { + $date += $date->month_last_day * ONE_DAY; } diff --git a/challenge-019/e-choroba/perl5/ch-2.pl b/challenge-019/e-choroba/perl5/ch-2.pl index d6705639d3..c1b1e9b76d 100755 --- a/challenge-019/e-choroba/perl5/ch-2.pl +++ b/challenge-019/e-choroba/perl5/ch-2.pl @@ -11,9 +11,7 @@ sub wrap_paragraph { if (length $paragraph <= $width) { $pos = length $paragraph; } else { - $pos = $width; - --$pos until ' ' eq substr $paragraph, $pos, 1 - or $pos < 0; + $pos = rindex $paragraph, ' ', $width; $pos = $width if $pos < 0; } $out .= substr $paragraph, 0, $pos, ""; |
