I’m trying to find an algorithm that will allow me to do the following:
Imagine I have 10 boolean variables, and I want to try every combination, since my goal is to find ANY combination which will give as a result to one of my methods true (This method has lots of restrictions, which is why I want to test every possible combinations, and if there are no combinations that will solve the problem, then I want to notify the user this).
I hope it is understandable!
I’m trying to find an algorithm that will allow me to do the following:
Share
I finally came up with a more efficient method: Using binary numbers:
Let’s say I want to test all possible boolean combinations out of 8 variables:
If I pick do the following I’ll get to test every combination:
This will go from 0 to 255, which in binary means going from 00000000 to 11111111
where each digit take the value 0 or 1, which can be represented as boolean. In this example if there’s no combination found the method will return null.