List Commands Library for 50g

05172019, 02:53 PM
(This post was last modified: 05172019 06:03 PM by DavidM.)
Post: #409




RE: List Commands Library for 50g
Here's a couple illustrative examples of how the masks I described above are used. I'm representing the masks in these examples as a string of numbers separated by spaces for clarity.
Combination Masks Example: a list of 5 items, we want all combinations of 3 Lexicographic stepping for DOCOMB/DOPERM combinations starts with the highest order form and works its way down to the lowest. So the first mask is created with a series of 1s that matches the count of selected elements, followed by 0s for the remainder: 1 1 1 0 0 The mask is then stepped down lexicographically in each iteration of the loop until the lowest order form is found: 1 1 1 0 0 1 1 0 1 0 1 1 0 0 1 ... 0 1 1 0 1 0 1 0 1 1 0 0 1 1 1 The mask for each iteration is applied to the source list such that the resulting selection contains only the elements that correspond to the 1s. So if our source list is: { A B C D E } ...then the resulting combinations that correspond to the iterative masks are: Code: Src List/Mask Resulting Sublist Permutation Masks Example: a list of 4 items The first mask is generated with each index matching its zerobased starting position, and is thus already in the lowestorder form: 0 1 2 3 The mask is then stepped lexicographically upward until the highest order permutation is encountered: 0 1 2 3 0 1 3 2 0 2 1 3 ... 3 1 2 0 3 2 0 1 3 2 1 0 The mask is applied to the source list in a similar fashion to the above description for combinations, but instead of a binary disposition (include/exclude), the mask designates the final positions of each of the source elements in the new list. So if our source list is: { A B C D } ...then the resulting permutation lists that correspond to the designated masks are as follows: Code: Src List/Mask Resulting Permutation Stepping algorithm The heart of all of this is a subroutine I called "NextMask", which takes a mask and a boolean indicating up/down stepping and returns the next mask and a boolean indicating if the new mask is at the high/low extreme. The algorithm is a modified form of this one, with the modifications allowing for up or down stepping. No changes were needed to accommodate combinations and permutations; the exact same algorithm inherently works for both so long as they are formatted as described above. Hope this helps! 

« Next Oldest  Next Newest »

User(s) browsing this thread: 2 Guest(s)