CODE
//list logic
//By Very Keynes - Please use or modify freely
//
list l1 = ["a","b","c","d"]; //test lists
list l2 = ["a","1","b","2","c","3"];
list ListXorY(list lx, list ly) // add the lists eleminating duplicates
{
list lz = []; integer x;
for (x = 0; x < llGetListLength(ly); ++x)
{
if (~llListFindList(lx,llList2List(ly,x,x))){;}
else {lz = lz + llList2List(ly,x,x);}
}
return lx + lz;
}
list ListXandY(list lx, list ly) // return a list of elements common to both lists
{
list lz = []; integer x;
for (x = 0; x < llGetListLength(ly); x++)
{
if (~llListFindList(lx,llList2List(ly,x,x))){lz = lz + llList2List(ly,x,x);}
else {;}
}
return lz;
}
list ListXnotY(list lx, list ly) // return elements in X that are not in Y
{
list lz = []; integer x;
for (x = 0; x < llGetListLength(lx); x++)
{
if (~llListFindList(ly,llList2List(lx,x,x))){;}
else {lz = lz + llList2List(lx,x,x);}
}
return lz;
}
list ListXxorY(list lx, list ly) // reteurn elements that are in X or Y but not both
{
return ListXnotY( lx, ly) + ListXnotY( ly, lx);
}
integer ListXequY(list lx, list ly)
{
if(llList2CSV(ListXnotY(lx,ly))=="")return TRUE;
else return FALSE;
}
integer ListXneqY(list lx, list ly)
{
if(llList2CSV(ListXnotY(lx,ly))=="")return FALSE;
else return TRUE;
}
// Code used to test the above
default
{
state_entry()
{
llOwnerSay("testing functions");
llOwnerSay("Elements in x = " + llList2CSV(l1));
llOwnerSay("Elements in y = " + llList2CSV(l2));
llOwnerSay("Elements in x or y = " + llList2CSV(ListXorY(l1,l2)));
llOwnerSay("Elements in both x and y = " + llList2CSV(ListXandY(l1,l2)));
llOwnerSay("Elements that are in x but not in y = " + llList2CSV(ListXnotY(l1,l2)));
llOwnerSay("Elements that are in y but not in x = " + llList2CSV(ListXnotY(l2,l1)));
llOwnerSay("Elements that are in x or y but not both = " + llList2CSV(ListXxorY(l1,l2)));
llOwnerSay("list x == y = " + (string)ListXequY(l1,l2));
llOwnerSay("list x == x = " + (string)ListXequY(l1,l1));
llOwnerSay("list y != x = " + (string)ListXneqY(l2,l1));
llOwnerSay("list y != y = " + (string)ListXneqY(l2,l2));
}
}