Robbie Hatley's Perl Solutions To The Weekly Challenge #208

For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle, usually with two parts, cycling every Sunday. You can find it here:

The Weekly Challenge

This week (2023-03-12 through 2023-03-18) is weekly challenge #208.

Task 1 is "Write a script to find all common strings between a pair of lists of string with minimum index sum. If no common strings are found, return an empty list." I found this very straightforward. Just a matter of arrays of arrays of arrays and nested for loops:

Task 1 Solution Source Code

Task 2 is "Write a script to return the duplicate integer and missing integer in an array which supposedly has one missing integer and one duplicate integer, or return -1 if the numbers of missing and duplicate integers are not both 1." I found this much tricker than Task 1 because of the inherent vagueness of what "missing" means, and because the answers given in Example 3 (see source below) force assumtions not given in the instructions. After working out exactly what the program was supposed to do, the rest was relatively straightforward, just a matter of finding "duplicate" and "missing" integers and pushing them to arrays:

Task 2 Solution Source Code

That's it for 208; see you on 209.

Comments

Popular posts from this blog

Robbie Hatley's Solutions To The Weekly Challenge #215

Robbie Hatley's Solutions To The Weekly Challenge #221

Robbie Hatley's Solutions To The Weekly Challenge #239