aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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";