aboutsummaryrefslogtreecommitdiff
path: root/challenge-019
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2019-08-04 18:59:04 +0100
committerGitHub <noreply@github.com>2019-08-04 18:59:04 +0100
commit496a7b2bb41c619e692075bfaaf111cb367231bf (patch)
treed8f8becd6782ebccee0a5466fc09b2d2956b9d97 /challenge-019
parent782ed88237f69ea4661aede77d8591838bbedfae (diff)
parentfeb91c7c98cba97a7cf2f2f5360c5e487dea1992 (diff)
downloadperlweeklychallenge-club-496a7b2bb41c619e692075bfaaf111cb367231bf.tar.gz
perlweeklychallenge-club-496a7b2bb41c619e692075bfaaf111cb367231bf.tar.bz2
perlweeklychallenge-club-496a7b2bb41c619e692075bfaaf111cb367231bf.zip
Merge pull request #468 from threadless-screw/wk19
Solutions wk19ch1-2 in Perl6
Diffstat (limited to 'challenge-019')
-rw-r--r--challenge-019/ozzy/perl6/ch-1.p615
-rw-r--r--challenge-019/ozzy/perl6/ch-2.p629
2 files changed, 44 insertions, 0 deletions
diff --git a/challenge-019/ozzy/perl6/ch-1.p6 b/challenge-019/ozzy/perl6/ch-1.p6
new file mode 100644
index 0000000000..7c5bdcd21d
--- /dev/null
+++ b/challenge-019/ozzy/perl6/ch-1.p6
@@ -0,0 +1,15 @@
+#!/usr/bin/env perl6
+#
+# Script to display months from the year 1900 to 2019 where you find 5 weekends,
+# i.e. 5 Fridays, 5 Saturdays and 5 Sundays.
+#
+# Months have a maximum of 31 days; for 5 weekends to fit in a 31-day month, the (31-4*7=)
+# 3 days at the extremities of the month should also be a weekend, i.e. the first day of
+# a 31-month day should be a Friday.
+
+for 1900..2019 -> $year {
+ for 1..12 -> $month {
+ my $d = Date.new($year,$month,1);
+ say "$d.year()/$d.month()" if $d.day-of-week == 5 && $d.days-in-month == 31;
+ }
+} \ No newline at end of file
diff --git a/challenge-019/ozzy/perl6/ch-2.p6 b/challenge-019/ozzy/perl6/ch-2.p6
new file mode 100644
index 0000000000..8470a103e7
--- /dev/null
+++ b/challenge-019/ozzy/perl6/ch-2.p6
@@ -0,0 +1,29 @@
+#!/usr/bin/env perl6
+#
+# Wrap paragraph provided on stdin using greedy algorithm
+#
+
+ my @words = do { slurp.words };
+ my $word_width = 0;
+
+ my $line_width = 20;
+ my $space_left = $line_width;
+ my $space_width = 1;
+
+
+for @words -> $w {
+
+ $word_width = $w.chars;
+ if ( ($space_left < $line_width) && ($space_width + $word_width <= $space_left) )
+ {
+ printf " $w";
+ $space_left -= ( $space_width + $word_width );
+ }
+ else
+ {
+ printf "{ $space_left == $line_width ?? "" !! "\n" }$w";
+ $space_left = $line_width - $word_width;
+ };
+}
+
+printf "\n";