diff options
| author | Mark Anderson <mark@frontrangerunner.com> | 2019-12-08 13:53:52 -0700 |
|---|---|---|
| committer | Mark Anderson <mark@frontrangerunner.com> | 2019-12-08 13:53:52 -0700 |
| commit | 100ef70f0287ea7028ad50e9edd2f38e07a62c9d (patch) | |
| tree | f6c838767f8748ffd5fd8d2df497c7b9fd6db334 /challenge-037 | |
| parent | 6c74ae80f5c6808f655e945d65a739af8faf59ea (diff) | |
| download | perlweeklychallenge-club-100ef70f0287ea7028ad50e9edd2f38e07a62c9d.tar.gz perlweeklychallenge-club-100ef70f0287ea7028ad50e9edd2f38e07a62c9d.tar.bz2 perlweeklychallenge-club-100ef70f0287ea7028ad50e9edd2f38e07a62c9d.zip | |
My 1st attempt at Raku
Diffstat (limited to 'challenge-037')
| -rw-r--r-- | challenge-037/mark-anderson/perl6/ch-1.p6 | 20 | ||||
| -rw-r--r-- | challenge-037/mark-anderson/perl6/ch-2.p6 | 21 |
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; +} |
