How to get the difference between two lists?

Dar Scott dsc at swcp.com
Sun Apr 3 23:44:18 EDT 2005


On Apr 3, 2005, at 9:04 PM, Ken Ray wrote:

> I can of course do a repeat loop through the small list and remove 
> those
> items from the comprehensive list, but I'm wondering if there's a 
> faster way
> to do this.

Some wild ideas:

1.  Convert the smaller list into a regex and use replaceText().

2.  Convert the long list to an array and loop through the smaller one 
and delete.  Oh, wait, that's a loop.

3.  Represent sets as arrays spanning the universe of numbers for your 
lists.  Represent your sets with these.  If a number is in the set, the 
value is 1.  If not, the value is 0.  Define intersection as *.  Define 
complement as take away one and times -1.  The set difference is the 
intersection with the complement of the set to be taken away.  Remember 
* and + can apply to arrays.

4.  Represent sets as a string of bits, 8 bits per char in a string.  
Use binaryDecode and binaryEncode and bitAnd and bitNot and loop 32 
bits at a time.  Whoops, that's looping, but each pass takes care of 32 
values in your universe.

5.  Take the middle line of the small list and find it or where it 
would be in the big list.  Concatenate the result of recursion of 
applying your function to the fronts and to the backs, where those do 
not include the middle line.

6.  I know it involves loops, but I have looped through both loops 
together and that was satisfactory for what I was doing, but I was not 
that happy with it.

Dar


-- 
**********************************************
     DSC (Dar Scott Consulting & Dar's Lab)
     http://www.swcp.com/dsc/
     Programming Services and Software
**********************************************



More information about the use-livecode mailing list