Perl Weekly Challenge - 037
Kian Meng, Ang
Posted on December 17, 2019
Originally published in kianmeng.org and Perl Weekly Challenge.
Continues from previous week.
Feel free to submit a merge request or open a ticket if you found any issues with this post. We highly appreciate and welcome your feedback.
For a quick overview, go through the original tasks and recap of the weekly challenge.
Additional feedback to the our Perl Weekly Challenge’s Twitter account is much appreciated.
Task #1
CPAN modules used: Data::Dumper
, Date::Manip
, DateTime
, DateTime::Duration
, DateTime::Event::Recurrence
, Function::Parameters
, List::Util
, Modern::Perl
, POSIX
, Test::More
, Time::Local
, Time::Moment
, Time::Piece
, Time::Seconds
, Time::localtime
, constant
, feature
, strict
, utf8
, warnings
This is a similar task to the previous challenges. Thus, we observed some participants reuse the same code with some modifications.
For a start, look at the solution by Ryan Thompson and Colin Crain which were heavily commented. This should provides us with some context and their thought on solving this tasks. Similarly but in blog post, read the write-up by Laurent Rosenfeld, E. Choroba, and Arne Sommer. They provides us with even more insight on how they approached this task.
And as usual, a few things that caught our attention.
The Date::Manip::Recur
CPAN module used by Colin Crain was rather interesting and unique compare to typical CPAN modules found in most submitted solutions. The CPAN module provides a way to parse and manipulate recurrence which was used by the participant to filter out all weekdays.
my $recur = new Date::Manip::Recur;
$recur->parse("0:0:0:1*0:0:0*IBD","Jan 1 2019","Jan 1 2019","Dec 31 2019");
my @date = $recur->dates();
Now, if the above recurrence modifier string was rather obscure, look at the solution by Javier Luque which use the DateTime::Event::Recurrence
CPAN module. As shown below, the code is pretty much self-explanatory.
my $working_days =
DateTime::Event::Recurrence->weekly(
days => [1 .. 5]
);
For a purist solution (without using any CPAN modules), Adam Russell was the only particpant who seemed to achieve that feat.
Task #2
CPAN modules used: Astro::Coord::ECI
, Astro::Coord::ECI::Sun
, Astro::Coord::ECI::Utils
, Astro::Sunrise
, Data::Dumper
, DateTime
, DateTime::Duration
, DateTime::Event::Sunrise
, File::Slurp
, Function::Parameters
, Getopt::Long
, HTML::Parser
, HTML::TableExtract
, HTTP::Tiny
, LWP::Simple
, LWP::UserAgent
, List::Util
, Modern::Perl
, Mojo::UserAgent
, Pod::Usage
, String::Util
, Syntax::Construct
, Time::Local
, Time::Piece
, Time::Seconds
, URI
, WWW::Mechanize
, Web::Scraper
, constant
, feature
, integer
, strict
, utf8
, warnings
This task reminded us of the optional third task we used to have in previous challenges in using web services or APIs.
For this task, we can group the submitted solutions into three groups. Those who scrapped the daylight gain and loss data from the Interweb, those who scrapped and pre-cached, or those who calculate dynamically.
Participants who approached this task with the first approach were Mark Anderson, Javier Luque, Adam Russell, Ruben Westerberg, Saiftynet, and E. Choroba.
Participants who pre-cached the daylight data were Laurent Rosenfeld, Andrezgz, and Colin Crain.
Participants who opted to calculate daylight details dynamically were Dave Jacoby, Roger Bell West, Lubos Kolouch, Ryan Thompson, and Duncan C White.
Again, certain solutions that caught our attentions.
The forward-looking statement or safe habour statement found in the submission by Colin Crain was rather intriguing and justifiable due to the uncertainties in predicting the daylight result.
Ryan Thompson basically wrote a console app or rather a CPAN module to calculate the difference of daylight between two months.
The solution by Mark Anderson is a short and practical demonstration of how MapReduce works.
See Also
(1) Perl Weekly Challenge - 037 by Javier Luque
(2) Weekdays, Daylight and Raku by Arne Sommer
(3) Weekdays and Daytimes by Adam Russell
(4) Sunrise and Sunset in Perl by Dave Jacoby
(5) Perl Weekly Challenge 37: Week Days in Each Month and Daylight Gain/loss by Laurent Rosenfeld
(6) Perl Weekly Challenge 37: weekdays and day lengths by Roger Bell West
(7) Perl Weekly Challenge 037: Weekdays and Daylight Gain/Loss by E. Choroba
Posted on December 17, 2019
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.