aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2019-08-02 22:49:56 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2019-08-02 22:49:56 +0100
commit61c53df732f5ac751eee2f5cef3ca3c98dfecfe2 (patch)
tree3119f9bf054153dcf05a3427af898eb8d443356e
parent58631924af586ed3313765ad5b164eec34e86ede (diff)
parent5507ab15a64ecd22067a19bc3b23779e9cf1af18 (diff)
downloadperlweeklychallenge-club-61c53df732f5ac751eee2f5cef3ca3c98dfecfe2.tar.gz
perlweeklychallenge-club-61c53df732f5ac751eee2f5cef3ca3c98dfecfe2.tar.bz2
perlweeklychallenge-club-61c53df732f5ac751eee2f5cef3ca3c98dfecfe2.zip
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
-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.")