aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-12-03 06:37:34 +0000
committerGitHub <noreply@github.com>2020-12-03 06:37:34 +0000
commitbd741a5f4d32158e3f7875d07dc8bf29e30256a5 (patch)
tree6f05a2b5754a443829e8a6dc23cf80dd54530352
parentf730f0dcb4f17c679952e5d93c0f1b03f250c32e (diff)
parentf62d0ca05c8c681af24fef2107bc87aa0a84bf1a (diff)
downloadperlweeklychallenge-club-bd741a5f4d32158e3f7875d07dc8bf29e30256a5.tar.gz
perlweeklychallenge-club-bd741a5f4d32158e3f7875d07dc8bf29e30256a5.tar.bz2
perlweeklychallenge-club-bd741a5f4d32158e3f7875d07dc8bf29e30256a5.zip
Merge pull request #2908 from stuart-little/stuart-little_037
1st commit on 037
-rw-r--r--challenge-037/stuart-little/README1
-rwxr-xr-xchallenge-037/stuart-little/raku/ch-1.p613
-rwxr-xr-xchallenge-037/stuart-little/raku/ch-2.p618
3 files changed, 32 insertions, 0 deletions
diff --git a/challenge-037/stuart-little/README b/challenge-037/stuart-little/README
new file mode 100644
index 0000000000..78439907de
--- /dev/null
+++ b/challenge-037/stuart-little/README
@@ -0,0 +1 @@
+Solutions by Stuart Little
diff --git a/challenge-037/stuart-little/raku/ch-1.p6 b/challenge-037/stuart-little/raku/ch-1.p6
new file mode 100755
index 0000000000..e301a1a3f5
--- /dev/null
+++ b/challenge-037/stuart-little/raku/ch-1.p6
@@ -0,0 +1,13 @@
+#!/usr/bin/env perl6
+use v6;
+
+sub nr_weekdays(Int $year, Int $month where 1 <= * <= 12) {
+ ((my $date=Date.new($year,$month,1))..$date.last-date-in-month).grep({ $_.day-of-week == (1..5).any }).elems
+}
+
+my $year=(@*ARGS) ?? (@*ARGS[0].Int) !! (DateTime.now.year);
+
+say $year;
+for (1..12).map({ $_ => nr_weekdays($year,$_) }) {.say}
+
+# run as <script> <year; defaults to current year>
diff --git a/challenge-037/stuart-little/raku/ch-2.p6 b/challenge-037/stuart-little/raku/ch-2.p6
new file mode 100755
index 0000000000..b94960c5d2
--- /dev/null
+++ b/challenge-037/stuart-little/raku/ch-2.p6
@@ -0,0 +1,18 @@
+#!/usr/bin/env perl6
+use v6;
+use HTTP::Tiny;
+
+sub sec_daylight($month,$year) {
+ my $url=qq{https://www.timeanddate.com/sun/uk/london?month=$month&year=$year};
+ my $response = HTTP::Tiny.new.get: $url;
+ $response<content>.decode ~~ m:g/\d+':'\d+':'\d+ <?before \< >/;
+ return $/.map({ ($_.split(':').map(*.Int) Z* (60 ** 2, 60, 1)).sum }).sum;
+}
+
+sub sec_to_hms(Int $sec where * >= 0) {
+ (($sec div (60 ** 2)), (($sec % (60 ** 2)) div 60), ($sec % 60));
+}
+
+say "Nov 2019 seconds of daylight: ", my $nov=sec_daylight(11,2019);
+say "Dec 2019 seconds of daylight: ", my $dec=sec_daylight(12,2019);
+say "Difference: {$dec - $nov} seconds, i.e. {((($dec-$nov).sign == -1) ?? "-" !! "")}(%s hours, %s minutes and %s seconds)".sprintf(|sec_to_hms(abs($dec-$nov)));