MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: Intersection and element counts

  • To: mathgroup at smc.vnet.net
  • Subject: [mg20745] Re: [mg20672] Re: [mg20615] Intersection and element counts
  • From: "Arnold Knopfmacher" <arnoldk at cam.wits.ac.za>
  • Date: Wed, 10 Nov 1999 00:17:54 -0500
  • Organization: MS, University of the Witwatersrand
  • Sender: owner-wri-mathgroup at wolfram.com

Here is my version:
myintersec[l1_, l2_] :=
  Table[#[[1]], {#[[2]]}] & /@ Take[#, {1, Length[#], 2}] &[
    Select[Sort[
        Join[{#[[1]] , Length[#]} & /@ Split[l1], {#[[1]] , Length[#]} &
            /@   Split[l2]]], MemberQ[Intersection[l1, l2], #[[1]]] &]]

l1 = {a, a, a, b, b, c, e}; l2 = {a, a, b, b, b, d, e};

myintersec[l1, l2]

{{a, a}, {b, b}, {e}}

Arnold Knopfmacher
Wits University
Arturas Acus [acus at itpa.lt] wrote:

> I am interesting in intersecion, which takes into
> account the number of the same elements.
>
> It is I would like
>
> myIntersection[{a,a,a,b,b,c},{a,a,b,b}]
>
> to give me {a,a,b,b}.



  • Prev by Date: Re: the new @@@ thing, MapApply?
  • Next by Date: Re: Don't change my definition of a function
  • Previous by thread: Re: Intersection and element counts
  • Next by thread: Re: Intersection and element counts