       Re: How to find the difference between two lists (opposite of union[]?)

• To: mathgroup at smc.vnet.net
• Subject: [mg119923] Re: How to find the difference between two lists (opposite of union[]?)
• From: "Tony Harker" <a.harker at ucl.ac.uk>
• Date: Wed, 29 Jun 2011 05:31:07 -0400 (EDT)
• References: <201106281155.HAA21477@smc.vnet.net>

```I'd probably use

mList = RandomInteger[{1, 1000}, 1000];
nList = Complement[Range, mList];
(* and, just to check: *)
Intersection[mList, nList]

Tony

]-> -----Original Message-----
]-> From: McHale, Paul [mailto:Paul.McHale at excelitas.com]
]-> Sent: 28 June 2011 12:55
]-> To: mathgroup at smc.vnet.net
]-> Subject: How to find the difference between two lists
]-> (opposite of union[]?)
]->
]-> I have been working through a neat book called Mathematica(r): A
]-> Problem-Centered
]-> Approach<http://www.amazon.com/Mathematica%C2%AE-Problem-
]-> Mathematics/dp/1849962502/ref=sr_1_2?ie=UTF8&qid=1309181549&sr=8-
]-> 2>.  I have a problem I would like to know if there is a more elegant
]-> solution.  I would think involving set theory, but I can't seem to
]-> (embarrassingly) find it.
]->
]-> I want to generate 1000 random integers between 1 and 1000.  Then find
]-> out what numbers between 1 and 1000 were not generated.
]->
]-> (* Generate random list of 1000 numbers  with range 1-1000*)
]-> mList=RandomInteger[{1,1000},1000] //Sort;
]->
]-> (* Find out what numbers were omitted in the range 1-1000*)
]-> (* Make a list of numbers 1-1000 with position of each within original
array
]-> *) mList=Table[{i,Position[mList,i] //Flatten},{i,1,1000}];
]->
]-> (* select numbers with no position in original array (musical chairs) *)
]-> Select[mList,Length[#[]]==0&][[All,1]]
]->
]-> This works creating a lot of extra array in the process.  Just wanted to
]-> what are the methods you guys would use to solve this?
]->
]-> A funny (non-working) way of stating the same thing would be:
]->
]-> (* Generate random list of 1000 numbers  with range 1-1000*)
]-> mList=RandomInteger[{1,1000},1000] //Sort;
]->
]-> Solve[ Join[mList,mDiff]==Range,mDiff]
]->
]-> Thanks,
]-> Paul
]->
]->
]-> Paul McHale  |  Electrical Engineer, Energetics Systems  |  Excelitas
]-> Technologies Corp.
]->
]-> Phone:   +1 937.865.3004   |   Fax:  +1 937.865.5170   |   Mobile:   +1
]-> 937.371.2828
]-> 1100 Vanguard Blvd, Miamisburg, Ohio 45342-0312 USA
]-> Paul.McHale at Excelitas.com<mailto:Paul.McHale at perkinelmer.com>
]-> www.excelitas.com<http://www.excelitas.com>
]->
]-> [cid:image001.png at 01CB9136.E3D96D90]
]->
]-> Please consider the environment before printing this e-mail.
]-> This email message and any attachments are confidential and proprietary
]-> to Excelitas Technologies Corp. If you are not the intended recipient of
this
]-> message, please inform the sender by replying to this email or sending a
]-> message to the sender and destroy the message and any attachments.
]-> Thank you

```

• Prev by Date: Re: How to find the difference between two lists (opposite of union[]?)
• Next by Date: Re: How to find the difference between two lists (opposite of union[]?)
• Previous by thread: Re: How to find the difference between two lists (opposite of union[]?)
• Next by thread: Re: How to find the difference between two lists (opposite of union[]?)