MathGroup Archive 2011

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

Search the Archive

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

  • To: mathgroup at smc.vnet.net
  • Subject: [mg119906] Re: How to find the difference between two lists (opposite of union[]?)
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Wed, 29 Jun 2011 05:27:59 -0400 (EDT)

Complement[Range@1000, RandomInteger[{1, 1000}, 1000]]

{1, 4, 5, 6, 9, 11, 13, 21, 22, 23, 25, 26, 30, 31, 32, 33, 35, 37, \
43, 44, 52, 53, 54, 55, 57, 59, 60, 61, 65, 66, 70, 72, 75, 77, 84, \
88, 94, 95, 96, 98, 101, 103, 104, 106, 122, 124, 125, 126, 128, 132, \
134, 135, 136, 139, 140, 143, 147, 154, 155, 158, 171, 173, 177, 178, \
184, 186, 187, 188, 189, 190, 192, 193, 194, 195, 203, 204, 208, 213, \
214, 226, 228, 235, 244, 245, 248, 250, 251, 253, 260, 261, 263, 266, \
267, 273, 275, 278, 279, 282, 284, 285, 289, 290, 292, 295, 297, 300, \
301, 308, 317, 318, 320, 321, 326, 332, 333, 334, 336, 344, 348, 349, \
350, 354, 357, 360, 361, 363, 364, 365, 367, 372, 373, 374, 375, 376, \
377, 383, 385, 387, 389, 391, 396, 399, 401, 403, 406, 407, 412, 416, \
418, 419, 420, 425, 426, 429, 430, 431, 433, 437, 440, 441, 443, 447, \
448, 449, 454, 455, 459, 465, 466, 475, 476, 477, 479, 481, 482, 484, \
485, 486, 490, 494, 499, 501, 504, 505, 506, 508, 510, 513, 514, 517,
  518, 519, 520, 525, 526, 529, 530, 532, 535, 536, 537, 540, 545, \
546, 547, 550, 552, 554, 556, 558, 569, 571, 581, 582, 590, 591, 597, \
600, 603, 604, 605, 607, 608, 611, 617, 619, 624, 629, 630, 636, 640, \
644, 646, 650, 651, 653, 654, 655, 660, 661, 662, 665, 667, 677, 681, \
685, 686, 687, 688, 699, 710, 714, 722, 725, 727, 728, 732, 733, 739, \
740, 741, 742, 744, 745, 747, 748, 749, 750, 753, 756, 759, 760, 761, \
763, 764, 766, 770, 771, 772, 780, 782, 786, 788, 789, 790, 794, 800, \
803, 804, 809, 810, 813, 824, 826, 835, 841, 846, 848, 849, 850, 852, \
854, 856, 864, 873, 875, 878, 883, 887, 889, 893, 894, 897, 899, 902, \
906, 909, 911, 913, 915, 920, 922, 924, 928, 930, 933, 934, 936, 938, \
940, 942, 943, 945, 947, 951, 953, 955, 957, 963, 964, 968, 969, 973, \
975, 976, 978, 982, 985, 987, 993, 994}

Bobby

On Tue, 28 Jun 2011 06:55:27 -0500, McHale, Paul  
<Paul.McHale at excelitas.com> wrote:

> I have been working through a neat book called Mathematica(r): A  
> Problem-Centered  
> Approach<http://www.amazon.com/Mathematica%C2%AE-Problem-Centered-Approach-Undergraduate-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[#[[2]]]==0&][[All,1]]
>
> This works creating a lot of extra array in the process.  Just wanted to  
> ask 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[1000],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


-- 
DrMajorBob at yahoo.com


  • Prev by Date: Re: How to write a "proper" math document
  • Next by Date: Re: Bug in Sum?
  • 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[]?)