39 lines
1.8 KiB
Text
39 lines
1.8 KiB
Text
Given <code>M</code> as a list of items and another list <code>N</code> of items chosen from <code>M</code>, create <code>M'</code> as a list with the ''first'' occurrences of items from N sorted to be in one of the set of indices of their original occurrence in <code>M</code> but in the order given by their order in <code>N</code>.
|
|
|
|
That is, items in <code>N</code> are taken from <code>M</code> without replacement, then the corresponding positions in <code>M'</code> are filled by successive items from <code>N</code>.
|
|
|
|
|
|
;For example:
|
|
:if <code>M</code> is <code>'the cat sat on the mat'</code>
|
|
:And <code>N</code> is <code>'mat cat'</code>
|
|
:Then the result <code>M'</code> is <code>'the mat sat on the cat'</code>.
|
|
|
|
The words not in <code>N</code> are left in their original positions.
|
|
|
|
|
|
If there are duplications then only the first instances in <code>M</code> up to as many as are mentioned in <code>N</code> are potentially re-ordered.
|
|
|
|
|
|
;For example:
|
|
: <code> M = 'A B C A B C A B C' </code>
|
|
: <code> N = 'C A C A' </code>
|
|
|
|
Is ordered as:
|
|
:<code> M' = 'C B A C B A A B C' </code>
|
|
|
|
<br>
|
|
Show the output, here, for at least the following inputs:
|
|
<pre>
|
|
Data M: 'the cat sat on the mat' Order N: 'mat cat'
|
|
Data M: 'the cat sat on the mat' Order N: 'cat mat'
|
|
Data M: 'A B C A B C A B C' Order N: 'C A C A'
|
|
Data M: 'A B C A B D A B E' Order N: 'E A D A'
|
|
Data M: 'A B' Order N: 'B'
|
|
Data M: 'A B' Order N: 'B A'
|
|
Data M: 'A B B A' Order N: 'B A'
|
|
</pre>
|
|
|
|
|
|
;Cf:
|
|
* [[Sort disjoint sublist]]
|
|
<br><br>
|