Robbie Hatley's Solutions, in Perl, for The Weekly Challenge #300 (Beautiful Permutations and Nested Arrays)
For those not familiar with "The Weekly Challenge", it is a weekly programming puzzle with two parts, cycling every Sunday. You can find it here: The Weekly Challenge The Weekly Challenge for the week of 2024-12-15 through 2024-12-21 is #300. The tasks for challenge #300 are as follows: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Task 300-1: Beautiful Arrangements Submitted by: Mohammad Sajid Anwar Description re-written by Robbie Hatley for clarity: Given a positive integer n, write a script to return the number of "beautiful arrangements" within the set of permutations of the sequence (1..n). A 1-indexed permutation of (1..n) is considered "a beautiful arrangement" if for every i (1 Other than the hassle of having to generate all of the permutations of (1..n), then counting how many of them are "beautiful arrangements", this is conceptually straightforward, if a bit complex (O(n!)). One snag is the requirement f...