aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2019-06-23 16:57:46 +0100
committerGitHub <noreply@github.com>2019-06-23 16:57:46 +0100
commit96bbd3135063a339600a6a3fbd5e7890b379ce98 (patch)
treefae623fd5c1d751b1add9f37978a54ac837590ca
parent3156381495f28075610d204d6de8a36405df6b82 (diff)
parent3997907e6b538494dac986a549cdb898f39a9d98 (diff)
downloadperlweeklychallenge-club-96bbd3135063a339600a6a3fbd5e7890b379ce98.tar.gz
perlweeklychallenge-club-96bbd3135063a339600a6a3fbd5e7890b379ce98.tar.bz2
perlweeklychallenge-club-96bbd3135063a339600a6a3fbd5e7890b379ce98.zip
Merge pull request #288 from fjwhittle/master
fjwhittle challenge 013 solutions
-rw-r--r--challenge-013/fjwhittle/perl6/ch-1.p616
-rw-r--r--challenge-013/fjwhittle/perl6/ch-2.p617
2 files changed, 33 insertions, 0 deletions
diff --git a/challenge-013/fjwhittle/perl6/ch-1.p6 b/challenge-013/fjwhittle/perl6/ch-1.p6
new file mode 100644
index 0000000000..fabce0666d
--- /dev/null
+++ b/challenge-013/fjwhittle/perl6/ch-1.p6
@@ -0,0 +1,16 @@
+#!/usr/bin/env perl6
+
+use v6;
+
+my enum Weekdays «:Monday(1) Tuesday Wednesday Thursday Friday Saturday Sunday»;
+
+#| Print out the date of the last Friday of every month in a given year
+unit sub MAIN (
+ UInt $year = Date.today.year #= Defaults to today's year
+);
+
+sprintf('%4d/%02d/%02d', .year, .month, .day).put
+ for (Date.new(:$year:1month:25day)..Date.new(:$year:12month:31day))
+ .grep: {
+ .day-of-week == Friday and .day > .days-in-month - 7
+ }
diff --git a/challenge-013/fjwhittle/perl6/ch-2.p6 b/challenge-013/fjwhittle/perl6/ch-2.p6
new file mode 100644
index 0000000000..914548f324
--- /dev/null
+++ b/challenge-013/fjwhittle/perl6/ch-2.p6
@@ -0,0 +1,17 @@
+#!/usr/bin/env perl6
+
+use v6;
+
+multi F(0) { 1 }
+multi M(0) { 0 }
+
+my (%F, %M);
+multi F(UInt $n) { %F{$n} //= $n - M(F($n - 1)) }
+multi M(UInt $n) { %M{$n} //= $n - F(M($n - 1)) }
+
+unit sub MAIN (UInt $seqlength = 32);
+
+say ('F:', |(^$seqlength).map: &F).join(' ');
+say ('M:', |(^$seqlength).map: &M).join(' ');
+
+