How to implement the following comparison using Python 2
Input is composed of two groups:
- Different lists collected from Experiments.
- All accepted sequences of some of these elements.
How to filter all those lists from input group 1. for which any of the accepted sequences from input group 2 is a proper subsequence?
For example:
Group two (defined by user):
x = [3, 1, 6]
y = [2, 1, 6]
z = [3, 4, 6]
Group one (from Experiments):
a = [1, 2, 3, 5, 6, 7]
b = [2, 1, 4, 3, 1, 8, 6]
c = [6, 3, 5, 7, 8, 4, 2, 6]
d = [1, 2, 1, 3, 4]
We accept b
and c
because x
is a subsequence of b
and z
is a subsequence of c
. And likewise we reject a
and d
because none of the x
, y
or z
is a subsequence of either.
mysterious(a) should return [2,6] which is not acceptable as we didn't visit node 1 after 2
mysterious(b) should return [2,1,6] which is acceptable and so on
Another example(detailed):
To accept a certain set or list I need some elements that present some services.
ServiceA served by [ 3 , 2 ]
ServiceB served by [ 1 , 4 ]
ServiceC served by [ 6 ]
Total nodes available to end user [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ]
We ask him to choose a set or list from the total nodes. We will only accept any combination when the nodes which serve services appear in correct order or sequence.
So user could choose any set with unlimited number of nodes as long as: 1. the nodes are member from the total nodes. 2. the order of services will be correct.
example [1,4,5,"Node serve A", 7,1,2, "Node serve B", "Node serve C"]
or so the general form to accept a list or set is: [some elements, element serve service A, other elements, element service B, more elements, element service c, etc...]
and you can replace the node service element with any element from the correspondent set above * If that not clear please let me know and will explain in more examples.
Example three:
Lets think in a factory with 10 machines. The product need three different processes to be manufactured.
Every machine can do some of these processes or all it differs. Machine 1 can do process alpha, gama but not beta. Machine 2 can do only process alpha
Every raw material arrives need to find route through machines with condition that by end it should have the three processes done.
The processes must be in order so first do Alpha, beta, then at end Gama. we do route every time to avoid overloading machines.
so now I need a function to accept or reject certain route suggestions to enforce that every raw material go through the processes in correct order.
I can't of course make all possible combinations and then compare as this will consume time and can run for infinity.
Thanks