Author Topic: Check if two "occurences"  (Read 3317 times)

0 Members and 1 Guest are viewing this topic.

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Check if two "occurences"
« 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 ?
« Last Edit: July 28, 2013, 02:39:41 pm by Hayleia »
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline blue_bear_94

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 801
  • Rating: +25/-35
  • Touhou Enthusiast / Former Troll / 68k Programmer
    • View Profile
Re: Check if two "occurences"
« Reply #1 on: July 28, 2013, 02:58:48 pm »
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
« Last Edit: July 28, 2013, 03:06:01 pm by blue_bear_94 »
Due to dissatisfaction, I will be inactive on Omnimaga until further notice. (?? THP hasn't been much success and there's also the CE. I might possibly be here for a while.)
If you want to implore me to come back, or otherwise contact me, I can be found on GitHub (bluebear94), Twitter (@melranosF_), Reddit (/u/Fluffy8x), or e-mail (if you know my address). As a last resort, send me a PM on Cemetech (bluebear94) or join Touhou Prono (don't be fooled by the name). I've also enabled notifications for PMs on Omnimaga, but I don't advise using that since I might be banned.
Elvyna (Sunrise) 4 5%
TI-84+SE User (2.30 2.55 MP 2.43)
TI-89 Titanium User (3.10)
Casio Prizm User? (1.02)
Bag  東方ぷろの

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: Check if two "occurences"
« Reply #2 on: July 28, 2013, 03:07:28 pm »
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)).
« Last Edit: July 28, 2013, 03:13:00 pm by Hayleia »
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline blue_bear_94

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 801
  • Rating: +25/-35
  • Touhou Enthusiast / Former Troll / 68k Programmer
    • View Profile
Re: Check if two "occurences"
« Reply #3 on: July 28, 2013, 03:10:57 pm »
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.
Due to dissatisfaction, I will be inactive on Omnimaga until further notice. (?? THP hasn't been much success and there's also the CE. I might possibly be here for a while.)
If you want to implore me to come back, or otherwise contact me, I can be found on GitHub (bluebear94), Twitter (@melranosF_), Reddit (/u/Fluffy8x), or e-mail (if you know my address). As a last resort, send me a PM on Cemetech (bluebear94) or join Touhou Prono (don't be fooled by the name). I've also enabled notifications for PMs on Omnimaga, but I don't advise using that since I might be banned.
Elvyna (Sunrise) 4 5%
TI-84+SE User (2.30 2.55 MP 2.43)
TI-89 Titanium User (3.10)
Casio Prizm User? (1.02)
Bag  東方ぷろの

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: Check if two "occurences"
« Reply #4 on: July 28, 2013, 03:13:04 pm »
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.
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Check if two "occurences"
« Reply #5 on: July 28, 2013, 03:16:34 pm »
Hmm, maybe something like this? :
Code: [Select]
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.

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: Check if two "occurences"
« Reply #6 on: July 28, 2013, 03:19:39 pm »
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).
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Check if two "occurences"
« Reply #7 on: July 28, 2013, 03:26:25 pm »
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:
Code: [Select]
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.

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: Check if two "occurences"
« Reply #8 on: July 28, 2013, 03:30:09 pm »
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.
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s