Kian-Meng Ang Weekly Review: Challenge - 023

Sunday, Sep 8, 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.

Task #1

CPAN modules used: Carp, Const::Fast, Function::Parameters, Getopt::Long, Getopt::Std, List::Util, Modern::Perl, Regexp::Common, Test::Exception, Test::More, autodie, constant, experimental, feature, strict, utf8, warnings

Out of all submissions, Duane Powell‘s submission have the most appealing output which deserved mentioned on its own.

./ 5 5 9 2 8 1 6
order:  series:
1:      4,-7,6,-7,5
2:      -11,13,-13,12
3:      24,-26,25
4:      -50,51
5:      101

./ 10 1 2 3 4 5 6 7 8 9 10 10000
order:  series:
1:      1,1,1,1,1,1,1,1,1,9990
2:      0,0,0,0,0,0,0,0,9989
3:      0,0,0,0,0,0,0,9989
4:      0,0,0,0,0,0,9989
5:      0,0,0,0,0,9989
6:      0,0,0,0,9989
7:      0,0,0,9989
8:      0,0,9989
9:      0,9989
10:     9989

While we read through all the submitted solutions, we did not execute all the submitted scripts. And some participants have put great effort in touching up the output and it would be quite pity if we miss it somehow. Therefore, it would be nice if all participants can append their script output within the same submitted solution. The solution by Walt Mankowski, Duncan C White, and Steven Wilson were good examples of this.

Athanasius took great effort in validating the command line options. Probably the most comprehensive we’ve seen so far for a simple script. The use of Regexp::Common CPAN module was a nice touch to it.

E. Choroba‘s submission was the only answer with two implementations consists of recursive way and formulae with memoizing.

Which was your preferred way to generate the series?

By Ruben Westerberg.

for (0..$order-1) {
    @values=map( { reduce {$a-$b} @values[$_, $_-1];} 1..@values-1);

By Yet Ebreo.

(@list = map $list[$_]-$list[$_-1],1..$#list) for 1..$n;

Task #2

CPAN modules used: Carp, Const::Fast, Function::Parameters, List::Util, Math::BigInt, Math::Prime::Util, Memoize, Modern::Perl, bigint, experimental, feature, lib, ntheory, strict, utf8, warnings

Another prime number related question and some participants decided to reuse and adapt their solutions from previous challenges.

We can group the solution into three categories of using a CPAN module to find the factor, using a CPAN module to generate prime numbers, or reimplement everything without or minimum use of CPAN modules.

Participants that choose the first strategy were Mark Anderson and Athanasius.

Participants in the second group were Duane Powell, Roger Bell West, Yet Ebreo, Guillermo Ramos, Duncan C White, Kian Meng Ang, E. Choroba, and Joelle Maslak.

Participants that opted for non-CPAN modules solutions were Adam Russell, Daniel Mantovani, Ruben Westerberg, Laurent Rosenfeld, Walt Mankowski, Jaldhar H Vyas, Andrezgz, Colin Crain, and Randy Lauen.

In Athanasiussolution, there was this piece of code that caught our attention as shown below. First, the BEGIN block will execute first before any part of the code. Next, the $| or also known as $OUTPUT_AUTOFLUSH was turned on (non-zero value) to auto-flushing the current STDOUT output and a newline after every print. Mark Jason Dominus have written a good explanation on its usage.

    $| = 1;
    print "\n";

Task #3

CPAN modules used: Const::Fast, Encode, Function::Parameters, Getopt::Long, HTTP::Request, JSON, JSON::XS, LWP::Simple, LWP::UserAgent, List::UtilsBy, Modern::Perl, Mojo::UserAgent, Net::Curl::Simple, Time::HiRes, Tk, Tk::ROText, autodie, diagnostics, feature, open, strict, utf8, warnings

Compare to last challenge, we have more participants (10 to be exact) for this optional task. Besides the regular (Athanasius, Guillermo Ramos, Randy Lauen, and Joelle Maslak ), we have a few newcomers (Mark Anderson, Arne Sommer, Yet Ebreo, Duncan C White, Andrezgz, and Colin Crain).

As with all past weekly challenges, higher submission rate correlates with the difficulty of a task. We have lots of submission due to simplicity of this task, which was just a straightforward HTTP request. As we observed, the easier the task, participants will get more creative with their solutions.

Two submissions that caught our eyes on how the participants presented the poem. Athanasius decided to present the poem using Tk, a cross-platform and long forgotten GUI toolkit. Note that installation of the Tk CPAN module will take a while. Similarly, Guillermo Ramos choose to display random poem at the console but using a typewriter effect. You really need to try this out!

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

See Also

(1) Random Differential Decomposition with Perl 6 by Arne Sommer

(2) Perl Weekly Challenge - 023, Task #1 by Mark Senn

(3) Perl Weekly Challenge 023 by Adam Russell

(4) Perl Weekly Challenge # 23: Difference Series and Prime Factorization by Laurent Rosenfeld

(5) Perl Weekly Challenge: Week 23 by Jaldhar H Vyas

(6) RogerBW’s Blog: Perl Weekly Challenge 23 by Roger Bell West

(7) Perl Weekly Challenge W023 - Difference, Factors and Poem by Yet Ebreo

(8) Perl Weekly Challenge 023: Forward difference series & Prime decomposition by E. Choroba


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

Contact with me