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: Const::Fast
, Data::Dumper
, English
, Getopt::Long
, IO::All
, List::Util
, Modern::Perl
, Mojo::File
, feature
, strict
, utf8
, warnings
This was similar to last week challenge but at different granularity, counting character instead of word. Hence, those participants who’ve submitted their solutions last week will only need to tweak their answer a bit. Is there anything we can learn or observe for this week challenge? Yes, and quite a few things. This week we will compare similar approach between two or more participants which either share similar approach in solving the task or totally using the opposite way.
Fabrizio Poggi and Dave Cross showed us the opposite way of solving the problem through either hard-coded or dynamic way. A simple example of not using a loop against a loop. The submission by Fabrizio can be further refactored using the range of alphabet characters a..z
as found in solution by Duane Powell.
Duncan C. White and E. Choroba have similar approach which use double while
loop to split and count the frequency of character. The different was the coding style.
Andrezgz, Colin Crain, and Bwva took the same approach of finding all characters in a line from a file, splitting it into an array of characters, and lowercase it before counting the frequency. Again, subtle differences in the personal coding style between them.
Adam Russell and Nazareno Delucca also have a similar approach but the latter did it in a more dense and shorter version using map
function.
Steven Wilson and Burkhard Nickels. Between a solution that was written in an explicit manner against a implicit Perl one-liner. For maintainable code, the former is a better approach. Laurent Rosenfeld also have a few one-liner examples.
Mark Anderson and Burkhard Nickels on using different CPAN modules to read the input file. Mojo::File
and IO::All
, which is the better choice or we just stick to <>
then?
Some rather unique approach we noticed. The use of getc
by Javier Luque to read the next character of a file handler. And the use of \P{Alpha}
by Joelle Maslak and \p{XPosixLower}
that matches the full range of Unicode or non-English characters that are considered as alphabetic.
Task #2
CPAN modules used: Const::Fast
, Data::Dumper
, Getopt::Long
, Modern::Perl
, PDL
, PDL::NiceSlice
, Perl6::Form
, feature
, open
, strict
, utf8
, warnings
We’ve something similar and quite humourous in the past challenges, just show the result as it. And this week, that solution came from Lubos Kolouch. We can understand the difficulty of calculating, formatting, and displaying the multiplication table for this task.
For code readability (subjective view) and density, we found the solution by Duncan C. White and E. Choroba were easier to follow compare to others.
Instead of printf
function to format the layout of the table, Adam Russell opted for alternative solution using the Perl6::Form
CPAN module.
Look into the submission by Burkhard Nickels where he tried different approaches to generate the table. We love the use of PDL
and PDL::NiceSlice
CPAN module as well as his write-up on comparing different alternative ways in generating the multiplication table.
SEE ALSO
(1) Perl Weekly Challenge 033 by Adam Russell
(2) Addition and Multiplication with Raku by Arne Sommer
(3) Perl Weekly Challenge #33 Task #1: Count letters by Burkhard Nickels
(4) Perl Weekly Challenge 033: Count Letters & Formatted Multiplication Table by E. Choroba
(5) Perl Weekly Challenge: Week 33 by Jaldhar H. Vyas
(6) Perl Weekly Challenge – 033 by Javier Luque
(7) Perl Weekly Challenge 33: Count letters and Multiplication Tables by Laurent Rosenfeld
(8) RogerBW’s Blog: Perl Weekly Challenge 33 by Roger Bell_West