Kian-Meng Ang Weekly Review: Challenge - 020

Sunday, Aug 18, 2019| Tags: Perl

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.

We’re going to review thing a bit differently for this week by listing down all the CPAN modules used for a particular task. The modules usage reflects three things, the coding style of a participant (Function::Parameters) the common used module (Math::Prime::Util) to solve a particular problem, and the trend of module usage (Modern::Perl) which was seen quite often in the last few challenges.


Task #1


The CPAN modules used for this task were Modern::Perl, Const::Fast, Encode, List::Util, Carp, Function::Parameters, Data::Dumper and Test::More.

Participants (Mark Anderson, Gustavo Chaves, Guillermo Ramos, Andrezgz, E Choroba, and Joelle Maslak) whose solutions that can be turned into Perl one-liner (well, Jaldhar H. Vyas did it) due to the expressiveness of the regex and brevity of the code. Example of such approach was the solution by Gustavo Chaves as shown below. Note that $& is the variable that stores the matched string of the regex.

my $string = shift or die "Usage: $0 STRING\n";

say $& while $string =~ /(.)\g1*/g

Generally, the regex used (read up the good breakdown of the regex by Veesh Goodman and Mark Senn) to split and group these characters were quite similar. The difference and difficulty was on how to process the regex result. Roger Bell West used of pairmap function in his solution was quite unique as well.

Instead of using regex, some participants like Adam Russell, Duane Powell, Dave Jacoby, Daniel Mantovani, Ruben Westerberg, Lubos Kolouch, Pete Houston opted for non-regex approach. Longer code but with increased readability.

For a comparison between the two approaches within a solution, look into the submission by Feng Chang.


Task #2


The CPAN modules used for this task were Math::Factor::XS, ntheory, Thread, Math::Prime::Util, Memoize, Const::Fast, Getopt::Long, List::Util, Math::BigInt, Math::Prime::XS, Function::Parameters, Data::Dumper, Modern::Perl and integer (one of the Perl pragma or pragmatic modules).

For a mathematical background of this task, read the excellent write-up by Damian Conway.

As this task involved prime numbers, some participants have re-used (Adam Russell and Jaldhar H. Vyas) their solutions in previous tasks for primality test. Others were using the available function from CPAN modules to find the factors of a number.

For this week, Adam Russell again try another unconventional approach by generating the Amicable numbers using the power of threading. Read his note on using threads in either Perl 5 and Perl 6. We observed more and more participants were solving challenges in both Perl versions these days.


Task #3


The CPAN modules used for this task were Getopt::Long, Mojo::UserAgent, Mojo::Util, Path::Tiny, Perl6::Slurp and autodie.

Our regular participant to this task, Joelle Maslak was the only participant again with both Perl 5 and Perl 6 solutions. While both answers looks somewhat similar, the Perl 6 version looks more cleaner due to all the default and built-in features available in Perl 6 and Cro libraries.

For those who haven’t done this task before, do give it a try.


Blog Posts


Some write-ups by the regular participants.

(1) Solving two problems by Veesh Goldman

(2) Amicable Split with Perl 6 by Arne Sommer

(3) Perl Weekly Challenge - 020, Task #1 by Mark Senn

(4) Perl Weekly Challenge 020 by Adam Russell

(5) Perl Weekly Challenge - Week 20 by Dave Jacoby

(6) Perl Weekly Challenge # 20: Split String on Character Change and Amicable Numbers by Laurent Rosenfeld

(7) Perl Weekly Challenge: Week 20 by Jaldhar H. Vyas

(8) Perl Weekly Challenge 020: Split on change + amicable numbers by E. Choroba

(9) With friends like these… by Damian Conway

SO WHAT DO YOU THINK ?

If you have any suggestions or ideas then please do share with us.

Contact with me