"be consistent" | |
PerlMonks |
Re: Minimally changing combinationsby Eily (Monsignor) |
on Jun 28, 2017 at 09:06 UTC ( [id://1193772]=note: print w/replies, xml ) | Need Help?? |
That sounds Gray-ish. Except this article deals pretty well with cases where all subsets have the same number of elements, which does not seem to be your case according to your example. If I'm not wrong, when you have @right, a list where your ordering is respected, and @left, a list of elements you can use the following algorithm: Because you reverse the right part each time you change the left element, you are sure that only one element changes (the left part), because you'll either be using the last or first element of @right twice in a row. This lets you scale up your N-uples recursively. Which in perl gives:
I've just tested those sets and looked if I could find somewhere where the rule was not respected, my advice would be to test it properly though. And haukex's proposed solution might be better, the python page does mention gray coding so that's promising. Edit: and actually implementing that as a recursive sub is left as an exercise to the reader ;-)
In Section
Seekers of Perl Wisdom
|
|