primitive array: group if 2 primitives contains common array value

   1709   4   0
User Avatar
Member
1012 posts
Joined: April 2017
Offline
Hi!

if I have a bunch of primitives with array values like this:

prim 0: [5, 15, 132, 8]
prim 1: [0, 3, 522, 5]
etc.

…how do I verify if a primitive array contains a common value as another primitive? In this case, they both have the value “5” therefore they should be place in a group.

-Olivier
User Avatar
Member
2045 posts
Joined: Sept. 2015
Offline
If it's just the two primitives, you can run it over primitives with:
int Count, Count_A;
int S[], T[];

S = i[]@Test;
T = prim(geoself(), "Test", 1);

if(@primnum == 0)
{
for(Count = 0; Count < len(S); Count++)
{
for(Count_A = 0; Count_A < len(T); Count_A++)
{
if( T[Count] == S[Count_A] )
{
i@group_Common = 1;
setprimgroup(geoself(), "Common", 1, 1, "set");
}
}
}
}
User Avatar
Member
1012 posts
Joined: April 2017
Offline
Ah! So there wasn't an easy/simple function for that. I'll try to understand your example. Thanks a lot!

-Olivier
User Avatar
Member
900 posts
Joined: Feb. 2016
Offline
Python has a built-in function intersection that works with sets (have a look at method2)



https://www.geeksforgeeks.org/python-intersection-two-lists/ [www.geeksforgeeks.org]
User Avatar
Member
1012 posts
Joined: April 2017
Offline
Thanks Andr.

I'm learning vex (first time I've ever tried coding) so I'll avoid python.

-Olivier
  • Quick Links