Order disjoint list items: Difference between revisions

m (typo)
Line 172:
| ->
</pre>
=={{header|Perl 6}}==
<lang perl6>sub order-disjoint-list-items(\M, \N) {
my \bag = N.BagHash;
(bag{$_} && bag{$_}-- ?? N.shift !! $_ for M)
}
 
for q:to/---/.comb(/ [\S+]+ % ' ' /).map({[.words]})
the cat sat on the mat mat cat
the cat sat on the mat cat mat
A B C A B C A B C C A C A
A B C A B D A B E E A D A
A B B
A B B A
A B B A B A
---
-> $m, $n { say "\n$m ==> $n\n", order-disjoint-list-items($m, $n) }</lang>
{{out}}
<pre>the cat sat on the mat ==> mat cat
the cat sat on the mat
 
the cat sat on the mat ==> cat mat
the cat sat on the mat
 
A B C A B C A B C ==> C A C A
A B C A B C A B C
 
A B C A B D A B E ==> E A D A
A B C A B D A B E
 
A B ==> B
A B
 
A B ==> B A
A B
 
A B B A ==> B A
A B B A</pre>
 
=={{header|Python}}==
Anonymous user