From c78d67d093595edab30a61e8d7b1e1c7c1dda672 Mon Sep 17 00:00:00 2001 From: "E. Choroba" Date: Sun, 4 Aug 2019 00:06:33 +0200 Subject: Improve E. Choroba's solution according to his blog post --- challenge-019/e-choroba/blog.txt | 1 + challenge-019/e-choroba/perl5/ch-1.pl | 11 ++++++----- challenge-019/e-choroba/perl5/ch-2.pl | 4 +--- 3 files changed, 8 insertions(+), 8 deletions(-) create mode 100644 challenge-019/e-choroba/blog.txt 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, ""; -- cgit