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.
Out of curiosity, of all submitted solutions, which participant have the fastest implementation?
Before we answer that, a simple benchmark was conducted using the
time command through Perl v5.28.1 in Ubuntu 19.04 as shown below.
$ time perl ch-1.pl
The results ranked by the execution time.
Adam Russell: real 0m0.772s, user 0m0.713s, sys 0m0.040s
Yet Ebreo: real 0m5.163s, user 0m5.127s, sys 0m0.020s
Andrezgz: real 0m5.367s, user 0m5.360s, sys 0m0.000s
E. Choroba: real 0m8.269s, user 0m8.248s, sys 0m0.008s
Joelle Maslak: real 0m11.575s, user 0m38.341s, sys 0m0.286s
Guillermo Ramos: real 0m15.314s, user 0m15.029s, sys 0m0.280s
Colin Crain: real 0m25.039s, user 0m25.011s, sys 0m0.004s
Laurent Rosenfeld: real 0m50.939s, user 0m50.788s, sys 0m0.064s
Jaldhar H. Vyas: real 1m6.381s, user 1m6.241s, sys 0m0.053s
Athanasius: real 1m54.845s, user 1m54.437s, sys 0m0.264s
Ruben Westerberg: real 2m44.981s, user 2m44.287s, sys 0m0.452s
Duane Powell: real 4m17.133s, user 4m14.221s, sys 0m2.451s
Lars Balker: real 4m49.408s, user 4m48.077s, sys 0m0.384s
Roger Bell West: real 8m17.638s, user 8m15.932s, sys 0m0.484s
From the result above, Adam Russell’s solution yielded the best result by implementing Floyd-Warshall All Pairs Shortest Path algorithm through the
Graph CPAN module. Read his blog for further details.
For those who are curious about the number of combinations available, you can check the output of the solution by Athanasius.
$ perl ch-1.pl There are 70 different Pokémon names 1: 64 2: 153 3: 414 4: 1025 5: 2433 6: 5529 7: 11964 8: 24270 9: 46046 10: 81197 11: 131728 12: 194642 13: 260203 14: 311684 15: 331912 16: 310198 17: 249704 18: 169904 19: 96066 20: 43676 21: 15128 22: 3648 23: 416 The longest sequences of the 70 given Pokémon names contain 23 elements; e.g.: machamp, petilil, loudred, darmanitan, nosepass, seaking, girafarig, gabite, exe ggcute, emboar, relicanth, heatmor, registeel, landorus, simisear, rufflet, trap inch, haxorus, scrafty, yamask, kricketune, emolga, audino
Start with this YouTube video (via Adam Russell) to get an overview of the Chaocipher, the playing card cipher. For further understanding, look at Adam Russell’s solution, which was based on the simulation playing card of the cipher.
Once you’ve understood the fundamental concept of Chaocipher, start with the solution by Andrezgz which was well-written clean code, readable and easy to grasp the implementation details. Similarly, read the solution by Laurent Rosenfeld as well, slightly difference but with test cases. Next, move the solution by E. Choroba if you’re looking for an Object-Oriented (OO) approach. Now, if you are looking for working console program of the cipher, read the solution by Joelle Maslak. And lastly, go through all other submitted solutions. Compare and contrast.
That is the code reading sequence we will recommend for anyone who look at this task for the first time. However, your mileage may vary (YMMV).
(1) Pokemon Chiao, Perl 6 by Arne Sommer
(2) Pokemon Name Ladder by Adam Russell
(3) Chaocipher Card Simulation by Adam Russell
(4) Perl Weekly Challenge 25: Pokémon Sequence and Chaocipher by Laurent Rosenfeld
(5) RogerBW’s Blog: Perl Weekly Challenge 25 by Roger Bell West
(6) Perl Weekly Challenge W025 - Longest Pokemon Sequence, Chaocipher by Yet Ebreo
(7) Perl Weekly Challenge 025: Pokemon Sequence and Chaocipher by E. Choroba