I need a special intersectant operation for List other than Set.
There maybe some duplicate elements, also need to count instead of merging as Intersection
.
For example:
$a=\{1,{\color\red{2}},2,{\color\red{3}},{\color\red{3}},3,4,4,4\}$
$b=\{{\color\red{2}},{\color\red{3}},{\color\red{3}},5\}$
$c=\{{\color\red{2}},2,{\color\red{3}},{\color\red{3}},4,4\}$
One 2 and two 3 appear in all list.
So $a\sqcap b\sqcap c=\{2,3,3\}$.
My rough attemption:
ListIntersection[list__]:=Module[{tlist=Tally/@{list},elements},
elements=First/@Intersection[Sequence@@tlist,SameTest->(First[#1]==First[#2]&)];
take[a_,b_]:=a[[Sequence@@(FirstPosition[a,b]+{0,1})]];
min[b_]:=Min[take[#,b]&/@tlist];
Flatten[ConstantArray@@@Transpose[{elements,min/@elements}]]
]
Test set:
a={1,2,2,3,3,3,4,4,4};
b={2,3,3,5};
c={2,2,3,3,4,4};
ListIntersection[a,b,c]
Answer:
{2, 3, 3}