Kian-Meng Ang Weekly Review: Challenge - 036

Sunday, Dec 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.

Additional feedback to the our Perl Weekly Challenge’s Twitter account is much appreciated.

Task #1

CPAN modules used: Data::Validate::VIN, Function::Parameters, List::MoreUtils, List::Util, Readonly, Syntax::Construct, Test::Exception, Test::More, boolean, feature, strict, warnings

Read the background details on the Vehicle Identification Number (VIN) first.

Next, look at the submissions by Duane Powell and Lubos Kolouch. Try solve any problems in Perl with available CPAN module. For this task, there exists Data::Validate::VIN CPAN module. For those who are curious, you can reading the source code of the CPAN module and compare with all the submissions here.

Following that, for submissions with good readability and easy to follow code, look no further into the solution by Laurent Rosenfeld, Jaldhar H Vyas and Javier Luque. Observe their clean coding style.

For this task, we need to predefine a set of values. Compare these submissions by Adam Russell, Ruben Westerberg, and Duncan C White. See how they declare and initialize the hash table of the valid characters, weights, check digits, country codes, and manufacturers. We’re not sure how Duncan obtained the list of data, but that was a large and long list.

Now, besides reading the blog on how each participant solved this task, you can read the detail comments written in the submission by Burkhard Nickels and Colin Crain. These participants have put in great length in documenting their thoughts on solving this task.

When come to writing own test cases, look at the submission by Saif Ahmed, Steven Wilson, and E. Choroba. Reading these test cases will give us an idea on how the subroutines supposed to be used.

While we went through these submissions, the solution by Andrezgz caught our attention as shown below. CORE:: prefix will enforce only the built-in function, in this case, state to be used.

  CORE::state $trans_key = {
      A=> 1, B=> 2, C=> 3, D=> 4, E=> 5, F=> 6, G=> 7, H=> 8,
      J=> 1, K=> 2, L=> 3, M=> 4, N=> 5,        P=> 7,        R=> 9,
             S=> 2, T=> 3, U=> 4, V=> 5, W=> 6, X=> 7, Y=> 8, Z=> 9,

Task #2

CPAN modules used: Algorithm::Combinatorics, Algorithm::Knapsack, Box::Calc, Data::Dumper, Data::PowerSet, Function::Parameters, List::Util, Math::Combinatorics, Modern::Perl, Readonly, Test::Deep, Test::More, Tie::IxHash, constant, feature, strict, warnings

To understand the task at hand, read the background details of Knapsack Problem.

Start with the submission by Duncan C White (solved by hand), Adam Russell (simplest), and Colin Crain (detail step-by-step comment) to get an initial concept on how to solve it.

Next, using similar approach but coded in more verbose style, read the solutions by Ruben Westerberg, Saif Ahmed, Laurent Rosenfeld, Roger Bell_West, and Andrezgz.

Lastly, look into submissions which used CPAN modules (listed above) by Burkhard Nickels8, Mark Anderson, and Duane Powell. See how these CPAN modules helped in generating all possible combinations to the solutions.

Most unique approach came from E. Choroba which used an indicator function approach. Read his blog post for further details.


(1) Vin Knapsack Meets Raku by Arne Sommer

(2) VIN Validation by Adam Russell

(3) Perl Weekly Challenge #36 by Burkhard Nickels

(4) Perl Weekly Challenge 036: VIN Validation and the Knapsack Problem by E. Choroba

(5) Perl Weekly Challenge – Week 36 by Kevin Colyer

(6) Perl Weekly Challenge 36: Vehicle Identification Numbers (VIN) and the Knapsack Problem by Laurent Rosenfeld


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

Contact with me