In Maple 15, I have a nested list like this one (only 2 levels of nesting):
[[a,b],[c],[d,e,f]]
I want to create 6 lists from that one (the number of elements..), like these:
[[x,a,b],[c],[d,e,f]]
[[a,x,b],[c],[d,e,f]]
[[a,b],[x,c],[d,e,f]]
[[a,b],[c],[x,d,e,f]]
[[a,b],[c],[d,x,e,f]]
[[a,b],[c],[d,e,x,f]]
I tried but I have super complex loops and it doesn’t work.. any more brilliant idea?
I am writing this code on Maple 7, but it should work with pretty much any version of Maple. I feel that it is easier to do things by first stripping the original nested list into two simple lists:
It is easier to insert your extra elements into the new flat lists:
The resulting flat lists must be converted back into the nested lists. This can be done by writing a simple function:
With this function available, it is now easy to convert the prepared data into the required format:
I admit that this may not be the most elegant solution possible. Unfortunately, nothing simpler comes to my mind just now.