This is more of a thought exercise than a real problem.
I have 24 switches. The switches are arranged in pairs; 1 and 13, 2 and 14, and so on. Each switch has two possible values; off and on. If one switch in the pair is in the on position, the other must be in the off position. There will always be more than two switches in the on position, but never more than ten.
Is there an elegant way to list the possible combinations?
Each pair of switches has three possible states: off off; off on; on off. To generate all possible overall states, start counting in base 3 from 000 ... 000 to 222 ... 222 where there are 12 base 3 digits, each digit representing a pair of switches.
Putting in the limits on the numbers of on and off switches is more complex, and will probably have to be done by explicit counting, unless someone comes up with a better idea. You must have at least two non-zero digits and at most ten non-zero digits.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments