So I have lists A and B. A can have all, some, or none of the elements in B, and I want to remove all the elements in A from B. It would also be fine to get the indices of the elements in B that aren't in A. Can anybody think of a good way to do this that doesn't involve looping through one of the lists a million times?
I understood almost none of that, but here are a few tricks that I know of with lists…
If you look at A and B as sets, then what I think you are saying is that A is a subset of B and it is unknown if it is a proper subset or not. Your goal is to obtain B-A. Unfortunately, because the lists are not necessarily the same size, the only way I can think of would be this:
dim(L1→B For(A,1,B L2*(L2≠L1(A→L2 End SortD(L2 sum(L2≠0→dim(L2 If Ans L2 Pause Ans
There is probably a better way to do this, but I cannot think of it at the moment… Also, the downside is that if set B has 0, the 0 will get removed. If you want to keep the elements in the same order they were originally in, you can do:
dim(L1→B For(A,1,B L2*(L2≠L1(A→L2 End seq(x,x,1,dim(L2→L3 SortD(L2,L3 sum(L2≠0→dim(L2 Ans→dim(L3 If Ans Then SortA(L3,L2 L2 End Pause Ans
I hope that helps a little… sorry, my understanding of sets isn't all that great x.x
47%? Take a look and try to imagine how cool 100% will be. This has won zContest 2011 and made news on TICalc. This compromise between Assembly and BASIC parses like BASIC and is fast like assembly. Grammer 2
Ultimately, there isn't a whole lot you can do to avoid traversing the list unless it is sorted
"Reality is that which, when you stop believing in it, doesn't go away."
-Philip K. Dick