Omnimaga
Calculator Community => TI Calculators => TI-BASIC => Topic started by: Hayleia on July 28, 2013, 02:39:08 pm
-
(I don't post often in that board).
So, I have two lists of same length L, the X list and the Y list.
And so basically, I'd like that if (X(n),Y(n))=(X(m),Y(m)), a calculus on the list returns 0, and that if there are no (n,m) so that (X(n),Y(n))=(X(m),Y(m)), the calculus returns non-zero.
For example,
X={1,4,3,6,7}
Y={2,4,5,2,1}
returns 0.
But
X={1,4,3,1,7}
Y={2,4,5,2,1}
returns non-zero.
I thought about putting the lists in a matrix and using det (and the 0/non-zero would be swapped but anyway) but the problem is that
1,2
1,2
returns the same as
1,2
2,4
So do you have any ideas ?
-
The best I can think of right now is:
DelVar ZFor(I,1,dim(LX
For(J,1,I)
If (LX(J)=LX(I)) and (LY(I)=LY(J
1->Z
End
End
-
sum(not(abs(LX-LY
It doesn't work (both examples return 1) and it doesn't surprise me : doing LX-LY (and adding some commands after) would check if there is an equality X(n)=Y(n), but not (X(n),Y(n))=(X(m),Y(m)).
-
sum(not(abs(LX-LY
It doesn't work (both examples return 1) and it doesn't surprise me : doing LX-LY (and adding some commands after) would check if there is an equality X(n)=Y(n), but not (X(n),Y(n))=(X(m),Y(m)).
I misunderstood the question at first, so I edited my previous post.
-
The best I can think of right now is:
DelVar ZFor(I,1,dim(LX
For(J,1,I)
If (LX(J)=LX(I)) and (LY(I)=LY(J
1->Z
End
End
Well yeah, I know that this would work, but I was wondering if there was not a fast method.
-
Hmm, maybe something like this? :
SortA(L1,L2
sum(not(ΔList(L1) or ΔList(L2
EDIT: This assumes the lists have more than 1 element. Also, nice idea with the matrixfeytontias stuff.
-
Oh, I didn't know that SortA could have several arguments !
Thanks, indeed I think that "something like this" should work (if not your code, something similar).
-
If you use multiple arguments, the first list gets sorted, the other lists get their elements swapped around so that they stay with the elements in the first list. So if you want to make sure that the lists are set back to the same order they were in, you can do:
cumSum(binomcdf(dim(L1)-1,0→L3
SortA(L1,L2,L3
min(not(ΔList(L1) or ΔList(L2
SortA(L3,L1,L2
And that returns 1 if there are any duplicates, 0 otherwise, and keeps L1 and L2 unchanged.
-
Yeah, I can do that or use two temporary lists that I don't care if they get swapped (but that method would use more RAM).
Anyway, thanks, your code seem to work perfectly.