Let's say I have two lists:
I want to find legal permutations of combining these two list in a way that the ordering of the members of each list, is preserved. In other words I am looking for a function ConditionalPermutation such that:
as you can see, in this simple case, we have 4 elements altogether, so the total number of permutations are 4*3*2=12. Out of these half have 2 appearing before 1 and also half have b appearing before a. Therefore the list of interest has (24/2)/2=6 legal permutations. In general there could be multiple l_i lists and each would have a different size.
I can code it with an imperative implementation, but I am looking for a neater way of doing it in Mathematica.
Ideally I want the solution to accept a general condition, or potentially one for each input list.