aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-037/mark-anderson/perl6/ch-1.p620
-rw-r--r--challenge-037/mark-anderson/perl6/ch-2.p621
2 files changed, 41 insertions, 0 deletions
diff --git a/challenge-037/mark-anderson/perl6/ch-1.p6 b/challenge-037/mark-anderson/perl6/ch-1.p6
new file mode 100644
index 0000000000..c57d9a639e
--- /dev/null
+++ b/challenge-037/mark-anderson/perl6/ch-1.p6
@@ -0,0 +1,20 @@
+#!/usr/bin/env perl6
+use Date::Names;
+
+my $dt = DateTime.new(year => 2019, month => 1);
+my $dn = Date::Names.new;
+
+while ($dt.year == 2019) {
+ my $count = 0;
+ my $mon = $dn.mon($dt.month, 3);
+
+ while ($dn.mon($dt.month, 3) eq $mon) {
+ if ($dt.day-of-week < 6) {
+ $count++;
+ }
+
+ $dt = $dt.later(:day1);
+ }
+
+ say "$mon:$count days";
+}
diff --git a/challenge-037/mark-anderson/perl6/ch-2.p6 b/challenge-037/mark-anderson/perl6/ch-2.p6
new file mode 100644
index 0000000000..24683e2b4e
--- /dev/null
+++ b/challenge-037/mark-anderson/perl6/ch-2.p6
@@ -0,0 +1,21 @@
+#!/usr/bin/env perl6
+use HTTP::UserAgent;
+use DOM::Tiny;
+
+my $dt = DateTime.new(secs(11) - secs(12));
+
+say "Dec has " ~ ($dt.hour,$dt.minute,$dt.second).join(":") ~ " less daylight";
+
+sub secs($month) {
+ my $link = "https://www.timeanddate.com/sun/uk/london?month=$month&year=2019";
+
+ my $ua = HTTP::UserAgent.new;
+
+ my $dom = DOM::Tiny.parse($ua.get($link).content);
+
+ # load the 'Length' column values
+ my $c = $dom.find('td[class="c tr sep-l"]').map(*.text);
+
+ # convert the hh::mm::ss to seconds and sum them
+ $c.map({DateTime.new("1970-01-01T$_.subst(/^(\d):/, {0 ~ $0})").posix}).sum;
+}