aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-019/noud/perl6/ch-1.p616
-rw-r--r--challenge-019/noud/perl6/ch-2.p621
2 files changed, 37 insertions, 0 deletions
diff --git a/challenge-019/noud/perl6/ch-1.p6 b/challenge-019/noud/perl6/ch-1.p6
new file mode 100644
index 0000000000..0966ab2fdc
--- /dev/null
+++ b/challenge-019/noud/perl6/ch-1.p6
@@ -0,0 +1,16 @@
+# Write a script to display months from the year 1900 to 2019 where you find 5
+# weekends i.e. 5 Friday, 5 Saturday and 5 Sunday.
+
+my %months = <January February March April May June July August September
+ October November December>.pairs;
+
+for 1900 .. 2019 -> $year {
+ for 1 .. 12 -> $month {
+ my $date = Date.new($year, $month, 1);
+ # A month can only have 5 Fridays, Saturdays, and Sundays if the month
+ # contains of 31 days, and the first day of the month is a Friday.
+ if ($date.days-in-month == 31 and $date.day-of-week == 5) {
+ say "{$date.year} %months{$month - 1}";
+ }
+ }
+}
diff --git a/challenge-019/noud/perl6/ch-2.p6 b/challenge-019/noud/perl6/ch-2.p6
new file mode 100644
index 0000000000..ac661d25a9
--- /dev/null
+++ b/challenge-019/noud/perl6/ch-2.p6
@@ -0,0 +1,21 @@
+# Write a script that can wrap the given paragraph at a specified column using
+# the greedy algorithm.
+
+sub greedy_wrap($string, $width=79) {
+ my $line = "";
+ for $string.split(/\s+/) -> $word {
+ if ($line.chars == 0) {
+ $line = $word;
+ } elsif ($width >= $line.chars + $word.chars) {
+ $line = "$line $word";
+ } else {
+ $line.say;
+ $line = $word;
+ }
+ }
+ if ($line.chars > 0) {
+ $line.say;
+ }
+}
+
+greedy_wrap("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")