Robbie Hatley’s Solutions, in Perl, for The Weekly Challenge #400 (“Largest Interval” and “Minimum Genetic Mutation”)
For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle with two tasks, with a new pair of tasks each Monday. You can find it here: The Weekly Challenge
The Weekly Challenge for the week of 2026-11-09 through 2026-11-15 is #400. The tasks for this challenge are as follows:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 400-1: Largest Interval Submitted by: Ali Moradi You are given a positive integer. Write a script that generates a sequence of integers from 1 to given positive integer, filtering out any numbers that contain repeating digits (e.g., 11, 99, 100, and 101 are excluded) and return the biggest jump.
We don't need to store the integers in an array; we need only keep track of "longest interval seen so far".
Robbie Hatley's Perl Solution to The Weekly Challenge 400-1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 400-2: Minimum Genetic Mutation Submitted by: Mohammad Sajid Anwar You are given start and end gene string along with gene bank. Write a script to return the minimum number of mutations required to mutate from start to end gene. Return -1 if there is no such mutation. A gene must be in a bank to make it a valid gene string. A gene string can be represented by an 8-character long string, with choices from ‘A’, ‘C’, ‘G’, and ‘T’.
To solve this problem, I build non-repeating chains of genes such that each gene in a chain varies from the previous in exactly one base pair. I start by making all 0-step chains (and there will always be exactly one, which is the chain consisting of the starting gene only). For each number of steps, if a chain can be found ending with the desired "end" gene, I return the chain length. Else if no chains can be made of the current number-of-steps, I return -1. Else I stash my list of chains of current number-of-steps in an array of arrays of chains, I increment number-of-steps, and I try again.
Robbie Hatley's Perl Solution to The Weekly Challenge 400-2
That's it for challenge 400; see you on challenge 401!
Comments
Post a Comment