I have two lists of numbers:
$$\{i_1, i_2, i_3,i_4\}$$ and $$\{j_1,j_2,j_3,j_4\}$$
The problem I want to solve is: Inside a loop, if the following two conditions are satisfied, then it will do something I want, otherwise it just cycle the loop. The conditions are:
- Both lists contain four different numbers;
- If ignoring the ordering, in other words, we view these two lists as two set, then they are the same.
I want to find a very fast way to get the answer to the problem. I have very slow Fortran code as follows:
if (i2==i1) cycle
if (i3==i1) cycle
if (i3==i2) cycle
if (i4==i1) cycle
if (i4==i2) cycle
if (i4==i3) cycle
if (j2==j1) cycle
if (j3==j1) cycle
if (j3==j2) cycle
if (j4==j1) cycle
if (j4==j2) cycle
if (j4==j3) cycle
q1=0
q2=0
q3=0
q4=0
if (i1==j1)q1=1
if (i1==j2)q1=2
if (i1==j3)q1=3
if (i1==j4)q1=4
if (i2==j1)q2=1
if (i2==j2)q2=2
if (i2==j3)q2=3
if (i2==j4)q2=4
if (i3==j1)q3=1
if (i3==j2)q3=2
if (i3==j3)q3=3
if (i3==j4)q3=4
if (i4==j1)q4=1
if (i4==j2)q4=2
if (i4==j3)q4=3
if (i4==j4)q4=4
if (q1*q2*q3*q4==24)then
Something I want to do
endif
I think to find a good program, the following should also be considered as well as cutting down the number of instructions:
- The probability to have four different numbers in both lists are about 1/10;
- The probability to have for these two lists containing two same set of numbers are very small, about 10^(-11);
- I really have to do many loops.
Could someone help me out? I think a good idea can really boost the code.