aboutsummaryrefslogtreecommitdiff
path: root/challenge-019/ozzy
diff options
context:
space:
mode:
authorthreadless-screw <39702500+threadless-screw@users.noreply.github.com>2019-08-04 18:09:55 +0200
committerthreadless-screw <39702500+threadless-screw@users.noreply.github.com>2019-08-04 18:09:55 +0200
commitfeb91c7c98cba97a7cf2f2f5360c5e487dea1992 (patch)
tree45d8658f636b14a7926b3ee4b17deec7de389e6a /challenge-019/ozzy
parent2a666cfcaf61b6708bfcf9df02c31b4e104a4205 (diff)
downloadperlweeklychallenge-club-feb91c7c98cba97a7cf2f2f5360c5e487dea1992.tar.gz
perlweeklychallenge-club-feb91c7c98cba97a7cf2f2f5360c5e487dea1992.tar.bz2
perlweeklychallenge-club-feb91c7c98cba97a7cf2f2f5360c5e487dea1992.zip
Solutions wk19ch1-2 in Perl6
Diffstat (limited to 'challenge-019/ozzy')
-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";