Compare arrays

Post Reply
PontusLSE
Trader
Posts: 14
Joined: Wed Jun 11, 2014 5:04 pm

Compare arrays

Post by PontusLSE »

Hey guys, I´m trying to learn how to use arrays in Empty4 and I have now run into a problem I cant solve, I´d appreciate some input (its probably simple but I cant figure it out) :)


I have 3 arrays with filled with info.
I want to find out if there is any value in array 1 that is not present in any other array.

In the example below I want to find and print out the values 22 and 66 from array 1.

Code: Select all

Array1:               Array2:               Array3:            
index:value           index:value           index:value

0:11                  0:11                  0:11
1:22                  1:33                  1:33
2:33                  2:44                  2:55
3:44                  3:77                  3:77
4:55                                        4:88
5:66                                        5:99
6:77                    
dietcoke
Trader
Posts: 162
Joined: Tue Nov 15, 2011 9:59 pm

Compare arrays

Post by dietcoke »

PontusLSE » Thu Nov 26, 2015 6:52 pm wrote:Hey guys, I´m trying to learn how to use arrays in Empty4 and I have now run into a problem I cant solve, I´d appreciate some input (its probably simple but I cant figure it out) :)


I have 3 arrays with filled with info.
I want to find out if there is any value in array 1 that is not present in any other array.

In the example below I want to find and print out the values 22 and 66 from array 1.

Code: Select all

Array1:               Array2:               Array3:            
index:value           index:value           index:value

0:11                  0:11                  0:11
1:22                  1:33                  1:33
2:33                  2:44                  2:55
3:44                  3:77                  3:77
4:55                                        4:88
5:66                                        5:99
6:77                    

Utterly untested, but something like this??

Code: Select all

For(a=0;a<ArraySize(Array1);a++)
{
	if(ArrayFind(Array1[a],Array2)==-1)
	{
		if(ArrayFind(Array1[a],Array3)==-1)
		{
			print("Unique ", Array1[a]);
		}
	}
}

//+------------------------------------------------------------------+
int ArrayFind(int num, int& a[])   {
//+------------------------------------------------------------------+
 for (int i=0; i<ArraySize(a); i++)   {
   if (num == a[i])   return(i);
 }
 return(-1);
}
              
Image
PontusLSE
Trader
Posts: 14
Joined: Wed Jun 11, 2014 5:04 pm

Compare arrays

Post by PontusLSE »

Fantastic, works perfectly.

Thanks!
Post Reply

Return to “Coders Hangout”