Re: Generalizing Complement to handle multiple occurrences of elements
- To: mathgroup at smc.vnet.net
- Subject: [mg112475] Re: Generalizing Complement to handle multiple occurrences of elements
- From: "Tony Harker" <a.harker at ucl.ac.uk>
- Date: Thu, 16 Sep 2010 06:02:50 -0400 (EDT)
If the elements are ordered, as in your example, then this works. myComplement[a_, b_] := Flatten[Complement[Split[a], Split[b], SameTest -> #1[[1]] == #2[[1]] &]] Tony ]-> -----Original Message----- ]-> From: Mark Coleman [mailto:markspcoleman at gmail.com] ]-> Sent: 15 September 2010 09:38 ]-> To: mathgroup at smc.vnet.net ]-> Subject: [mg112425] Generalizing Complement to handle ]-> multiple occurrences of elements ]-> ]-> Greetings, ]-> ]-> I'm wondering how one can efficiently generalize the built-in ]-> Complement function to return multiple occurrences of elements. For ]-> instance, the current version generates ]-> ]-> a={1,2,2,3,4,4,4,4} ]-> b={3,5,7} ]-> ]-> Complement[a,b]={1,2,4} ]-> ]-> I'm looking for a way to define ]-> ]-> myComplement[a,b]={1,2,2,4,4,4,4} ]-> ]-> My current code is very inefficient! ]-> ]-> Thanks, ]-> ]-> Mark ]-> ]->