stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

Compare arrays
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=4516
Page 1 of 1
Author:  PontusLSE [ Thu Nov 26, 2015 6:52 pm ]
Post subject:  Compare arrays

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                    
Author:  dietcoke [ Thu Nov 26, 2015 8:45 pm ]
Post subject:  Compare arrays

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);
}
              
Author:  PontusLSE [ Thu Nov 26, 2015 9:43 pm ]
Post subject:  Compare arrays

Fantastic, works perfectly.

Thanks!
All times are UTC Page 1 of 1