To rearrange things with De Morgan's Laws, perform these three steps, in any order:
Negate each individual condition.
Toggle between AND and OR.
Negate the whole thing.
Starting with: !(x==y||x==z||y==z)
First I'd negate the whole thing: You would normally write this as !!(x==y||x==z||y==z) initially but this of course simplifies to just x==y||x==z||y==z so its easier to just take the outer NOT away.
Then I'd change the ORs to ANDs: x==y && x==z && y==z
Then I'd negate the individual expressions: You could write this as !(x==y) && !(x==z) && !(y==z) initially but I would just negate each individual expression by changing the comparison operator instead i.e. x!=y && x!=z && y!=z
Here's part of the general solution, with certain bits intentionally blanked out so that it cannot be copy'n'pasted without first understanding how it works. It also does not remove duplicates:
Code:
void void printPermutations(int arr[], int n, int pos = 0) {
if (?? == n) {
for (int i=0; ??<n; ++i)
printf("%d ", arr[??]);
printf("\n");
return;
}
for (int i=pos; i<??; ++i) {
swap(arr[??], arr[pos]);
printPermutations(arr, ??, pos+1);
swap(arr[i], arr[??]);
}
}