diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2019-07-30 19:20:32 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2019-07-30 19:20:32 +0100 |
| commit | 8e524f0d476c07fa2fc984cb10d47c08b609a1bc (patch) | |
| tree | 91e84e8a33a0d61cfdf96a474445ee19ac63f654 /challenge-019 | |
| parent | 0a3a46d3740c40406de84ea15a678a387a3cedb7 (diff) | |
| download | perlweeklychallenge-club-8e524f0d476c07fa2fc984cb10d47c08b609a1bc.tar.gz perlweeklychallenge-club-8e524f0d476c07fa2fc984cb10d47c08b609a1bc.tar.bz2 perlweeklychallenge-club-8e524f0d476c07fa2fc984cb10d47c08b609a1bc.zip | |
- Added solutions by Laurent Rosenfeld.
Diffstat (limited to 'challenge-019')
| -rw-r--r-- | challenge-019/laurent-rosenfeld/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-019/laurent-rosenfeld/perl5/ch-1.pl | 13 | ||||
| -rw-r--r-- | challenge-019/laurent-rosenfeld/perl5/ch-2.pl | 19 | ||||
| -rw-r--r-- | challenge-019/laurent-rosenfeld/perl6/ch-1.p6 | 13 | ||||
| -rw-r--r-- | challenge-019/laurent-rosenfeld/perl6/ch-2.p6 | 16 |
5 files changed, 62 insertions, 0 deletions
diff --git a/challenge-019/laurent-rosenfeld/blog.txt b/challenge-019/laurent-rosenfeld/blog.txt new file mode 100644 index 0000000000..f1080afc68 --- /dev/null +++ b/challenge-019/laurent-rosenfeld/blog.txt @@ -0,0 +1 @@ +http://blogs.perl.org/users/laurent_r/2019/07/perl-weekly-challenge-19-weekends-and-wrapping-lines.html diff --git a/challenge-019/laurent-rosenfeld/perl5/ch-1.pl b/challenge-019/laurent-rosenfeld/perl5/ch-1.pl new file mode 100644 index 0000000000..74709d868f --- /dev/null +++ b/challenge-019/laurent-rosenfeld/perl5/ch-1.pl @@ -0,0 +1,13 @@ +#!/usr/bin/perl +use strict; +use warnings; +use feature qw/say/; +use Time::Local; + +for my $year (0..119) { + for my $month ( 1, 3, 5, 7, 8, 10, 12) { + my $date = timegm (0, 0, 0, 1, $month - 1, $year); + say $year + 1900, "-", sprintf("%02d ", $month) + if (gmtime $date)[6] == 5; + } +} diff --git a/challenge-019/laurent-rosenfeld/perl5/ch-2.pl b/challenge-019/laurent-rosenfeld/perl5/ch-2.pl new file mode 100644 index 0000000000..a36c129d3e --- /dev/null +++ b/challenge-019/laurent-rosenfeld/perl5/ch-2.pl @@ -0,0 +1,19 @@ +#!/usr/bin/perl +use strict; +use warnings; +use feature qw/say/; + +sub wrap { + my ($line, $width) = @_; + my $out = ''; + while ($line) { + return $out . "$line\n" if length $line < $width; + my $pos = rindex $line, ' ', $width - 1; + $out = $out . substr($line, 0, $pos) . "\n"; + $line = substr $line, $pos+1; + } + return $out; +} + +my $in = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Dolor sed viverra ipsum nunc aliquet bibendum enim. In massa tempor nec feugiat. Nunc aliquet bibendum enim facilisis gravida. Nisl nunc mi ipsum faucibus vitae aliquet nec ullamcorper. Amet luctus venenatis lectus magna fringilla."; +say wrap $in, $_ for 60, 35; diff --git a/challenge-019/laurent-rosenfeld/perl6/ch-1.p6 b/challenge-019/laurent-rosenfeld/perl6/ch-1.p6 new file mode 100644 index 0000000000..cff7b26c75 --- /dev/null +++ b/challenge-019/laurent-rosenfeld/perl6/ch-1.p6 @@ -0,0 +1,13 @@ +use v6; + +for 1900..2019 -> $year { + for 1..12 -> $month { + my $day = 1; + my $date = Date.new($year, $month, $day); + my $last-day-of-month = + $date.later(month => 1).earlier(day => 1); + ++$date until $date.day-of-week == 5; + say $year, "-", $month.fmt("%02d"), " has 5 weekends" + if $last-day-of-month - $date > 29; + } +} diff --git a/challenge-019/laurent-rosenfeld/perl6/ch-2.p6 b/challenge-019/laurent-rosenfeld/perl6/ch-2.p6 new file mode 100644 index 0000000000..bfb7312eb6 --- /dev/null +++ b/challenge-019/laurent-rosenfeld/perl6/ch-2.p6 @@ -0,0 +1,16 @@ +use v6; + +sub wrap (Str $line is copy, Int $width) { + my $out = ''; + while ($line) { + return $out ~ "$line\n" if $line.chars < $width; + my $pos = rindex $line, ' ', $width - 1; + $out = $out ~ substr($line, 0, $pos) ~ "\n"; + $line = substr $line, $pos+1; + } + return $out; +} + +my $in = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Dolor sed viverra ipsum nunc aliquet bibendum enim. In massa tempor nec feugiat. Nunc aliquet bibendum enim facilisis gravida. Nisl nunc mi ipsum faucibus vitae aliquet nec ullamcorper. Amet luctus venenatis lectus magna fringilla."; + +say wrap $in, $_ for 60, 35; |
