diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2019-12-03 11:21:51 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-12-03 11:21:51 +0000 |
| commit | 01c96369da9863fef9d1c87d64743385a52126fa (patch) | |
| tree | 48f04906a1a621de5668742f24b8cf0705a13c12 /challenge-037 | |
| parent | 64323e5f5252aacbcbddacd6befe4acb33513c61 (diff) | |
| parent | e8cec2d28eac3c5357d2e3e55a15cc2d857db864 (diff) | |
| download | perlweeklychallenge-club-01c96369da9863fef9d1c87d64743385a52126fa.tar.gz perlweeklychallenge-club-01c96369da9863fef9d1c87d64743385a52126fa.tar.bz2 perlweeklychallenge-club-01c96369da9863fef9d1c87d64743385a52126fa.zip | |
Merge pull request #999 from andemark/master
challenge-037 solutions
Diffstat (limited to 'challenge-037')
| -rw-r--r-- | challenge-037/mark-anderson/perl5/ch-1.pl | 23 | ||||
| -rw-r--r-- | challenge-037/mark-anderson/perl5/ch-2.pl | 24 |
2 files changed, 47 insertions, 0 deletions
diff --git a/challenge-037/mark-anderson/perl5/ch-1.pl b/challenge-037/mark-anderson/perl5/ch-1.pl new file mode 100644 index 0000000000..93929dd4e4 --- /dev/null +++ b/challenge-037/mark-anderson/perl5/ch-1.pl @@ -0,0 +1,23 @@ +#!/usr/bin/env perl +use Modern::Perl '2018'; +use Time::Moment; + +my $tm = Time::Moment->new( + year => 2019, + month => 1 +); + +while($tm->year == 2019) { + my $count = 0; + my $month = $tm->strftime('%b'); + + while($tm->strftime('%b') eq $month) { + if($tm->day_of_week < 6) { + $count++; + } + + $tm = $tm->plus_days(1); + } + + say "$month:$count days"; +} diff --git a/challenge-037/mark-anderson/perl5/ch-2.pl b/challenge-037/mark-anderson/perl5/ch-2.pl new file mode 100644 index 0000000000..18be5de613 --- /dev/null +++ b/challenge-037/mark-anderson/perl5/ch-2.pl @@ -0,0 +1,24 @@ +#!/usr/bin/env perl +use Modern::Perl '2018'; +use Mojo::UserAgent; + +my $ua = Mojo::UserAgent->new; + +my $nov = "https://www.timeanddate.com/sun/uk/london?month=11&year=2019"; +my $dec = "https://www.timeanddate.com/sun/uk/london?month=12&year=2019"; + +# load the 'Length' column values into a collection +my $nov_c = $ua->get($nov)->result->dom->find('td[class="c tr sep-l"]')->map('text'); +my $dec_c = $ua->get($dec)->result->dom->find('td[class="c tr sep-l"]')->map('text'); + +# convert the values from hh:mm:ss to seconds +$nov_c->map(sub { $_ = Mojo::Date->new("1970-01-01T$_")->epoch }); +$dec_c->map(sub { $_ = Mojo::Date->new("1970-01-01T$_")->epoch }); + +# sum the seconds in each collection +my $nov_sum = $nov_c->reduce(sub { $a + $b }); +my $dec_sum = $dec_c->reduce(sub { $a + $b }); + +# make a date from the seconds difference and print the hh:mm:ss +my $hms = (split /\s/, Mojo::Date->new(abs($dec_sum - $nov_sum)))[4]; +say "Dec has $hms", $dec_sum > $nov_sum ? " more " : " less ", "daylight"; |
