I want to find symmetries in 4 integer variables i,j,k
and l
.
The symmetries are:
- all four numbers are equal: XXXX,
- three numbers are equal: XXXY,XXYX,XYXX,YXXX
- two pairs of equal numbers: XXYY,XYXY,XYYX,...
- one pair of equal numbers and two different numbers: XXYZ,XYXZ,XYZX,...
- all numbers are different.
All variables run within a certain non continuous range. I use nested if else statements. The first if checks for inequality of all variables. If not, then I have case 1. The next if checks if there are any equal pairs. If not, then case 5. The next if checks for three equal numbers. If true, then case 2. Otherwise, the last if checks for two pairs of equal numbers. If true, then case 3, otherwise case 4.
if(!(i==j && j==k && k==l)){
if(i==j || i==k || i==l || j==k || j==l || k==l){
if((i==j && j==k) || (i==j && j==l) || (i==k && k==l) || (j==k && k==l)){ ...//do something
}else{
if((i==j && k==l) || (i==k && j==l) || (i==l && j==k)){
...//do something
}else{
...//do something
}
}
}else{
...//do something
}
}else{
...//do something
}
Is there better way do do this? I mean better in the sense of better performance, because I have to do this test millions of times.