diff options
| author | chirvasitua <stuart-little@users.noreply.github.com> | 2020-12-02 18:27:56 -0500 |
|---|---|---|
| committer | chirvasitua <stuart-little@users.noreply.github.com> | 2020-12-02 18:27:56 -0500 |
| commit | f62d0ca05c8c681af24fef2107bc87aa0a84bf1a (patch) | |
| tree | 8c54371b96c5f9b0896fdc5ae98f69dbfae9c3f4 | |
| parent | beb477113a55cf04d20b5528c1749f3e1b5693ab (diff) | |
| download | perlweeklychallenge-club-f62d0ca05c8c681af24fef2107bc87aa0a84bf1a.tar.gz perlweeklychallenge-club-f62d0ca05c8c681af24fef2107bc87aa0a84bf1a.tar.bz2 perlweeklychallenge-club-f62d0ca05c8c681af24fef2107bc87aa0a84bf1a.zip | |
1st commit on 037
| -rw-r--r-- | challenge-037/stuart-little/README | 1 | ||||
| -rwxr-xr-x | challenge-037/stuart-little/raku/ch-1.p6 | 13 | ||||
| -rwxr-xr-x | challenge-037/stuart-little/raku/ch-2.p6 | 18 |
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))); |
