diff options
| -rwxr-xr-x | challenge-019/feng-chang/perl5/ch-1.pl | 13 | ||||
| -rwxr-xr-x | challenge-019/feng-chang/perl5/ch-2.pl | 46 | ||||
| -rwxr-xr-x | challenge-019/feng-chang/perl6/ch-1.p6 | 9 | ||||
| -rwxr-xr-x | challenge-019/feng-chang/perl6/ch-2.p6 | 33 |
4 files changed, 101 insertions, 0 deletions
diff --git a/challenge-019/feng-chang/perl5/ch-1.pl b/challenge-019/feng-chang/perl5/ch-1.pl new file mode 100755 index 0000000000..c7f0e45a77 --- /dev/null +++ b/challenge-019/feng-chang/perl5/ch-1.pl @@ -0,0 +1,13 @@ +#!/bin/env perl + +use Modern::Perl; +use Date::Manip; + +for my $year (1900 .. 2019) { + for my $month (1,3,5,7,8,10,12) { + my $d = ParseDate("$year/$month/1"); + if (UnixDate($d, '%w') == 5) { + say sprintf('%d-%02d has 5 weekends', $year, $month); + } + } +} diff --git a/challenge-019/feng-chang/perl5/ch-2.pl b/challenge-019/feng-chang/perl5/ch-2.pl new file mode 100755 index 0000000000..82f0b49419 --- /dev/null +++ b/challenge-019/feng-chang/perl5/ch-2.pl @@ -0,0 +1,46 @@ +#!/bin/env perl + +use Modern::Perl; +use Getopt::Long; + +my $max_width = 80; +GetOptions( + 'width:s' => \$max_width, +); + +my $p; +{ + local $/; + undef $/; + $p = <DATA>; +} + +wrap_text($p, $max_width); + +sub wrap_text { + my ($p, $max_width) = @_; + + my $line = ''; + for my $word (split /\s+/, $p) { + die "max_width must be longer than word width: $word\n" if length($word) > $max_width; + + if ($max_width < length($line) + 1 + length($word)) { + say $line; + $line = $word; + } else { + $line .= length($line) == 0 ? $word : " $word"; + } + } + say $line if $line; +} + +__DATA__ +Use the resources to learn Perl 6 and write about your experience +along the way! Let us know when you do write something if you +want to share it with the larger Perl 6 community (you should!). +Some writing topics could be programs you've written, tricks +you've learned, cool things about the Perl 6, etc. Because of your +fresh perspective as a learner, writing educational/training +material would be a great idea as well. If anything is Less Than +Awesome in your experience you can chat with us, or open an issue +on the User Experience repository. diff --git a/challenge-019/feng-chang/perl6/ch-1.p6 b/challenge-019/feng-chang/perl6/ch-1.p6 new file mode 100755 index 0000000000..1322a90bb3 --- /dev/null +++ b/challenge-019/feng-chang/perl6/ch-1.p6 @@ -0,0 +1,9 @@ +#!/bin/env perl6 + +for 1900..2019 -> $year { + for 1,3,5,7,8,10,12 -> $month { + if Date.new($year, $month, 1).day-of-week == 5 { + say sprintf('%d-%02d has 5 weekends', $year, $month); + } + } +} diff --git a/challenge-019/feng-chang/perl6/ch-2.p6 b/challenge-019/feng-chang/perl6/ch-2.p6 new file mode 100755 index 0000000000..89df0253ef --- /dev/null +++ b/challenge-019/feng-chang/perl6/ch-2.p6 @@ -0,0 +1,33 @@ +#!/bin/env perl6 + +constant \Paragraph = q:to/END/; +Use the resources to learn Perl 6 and write about your experience +along the way! Let us know when you do write something if you +want to share it with the larger Perl 6 community (you should!). +Some writing topics could be programs you've written, tricks +you've learned, cool things about the Perl 6, etc. Because of your +fresh perspective as a learner, writing educational/training +material would be a great idea as well. If anything is Less Than +Awesome in your experience you can chat with us, or open an issue +on the User Experience repository. +END + +sub wrap-text(Str:D $paragraph, UInt:D $max-width) { + my Str $line = ''; + + for $paragraph.words -> $word { + die "max-width must be longer than word width: $word" if $word.chars > $max-width; + + if $max-width < $line.chars + 1 + $word.chars { + say $line; + $line = $word; + } else { + $line ~= $line.chars == 0 ?? $word !! " $word"; + } + } + say $line if $line; +} + +sub MAIN(UInt $max-width = 80) { + wrap-text(Paragraph, $max-width); +} |
