This is such an obscure problem that I suspect that I will have to do it at a different level in my code ... but I hope the hive mind, which is a stack overflow, can help ...
I have a long one, which, if expressed as a binary string, will have exactly five bits. For instance,
long l = 341;
I am looking for an array containing all ten possible lengths that set exactly three of these bits. To continue this example,
long[] results = {
101010000,
101000100,
101000001,
100010100,
100010001,
100000101,
1010100,
1010001,
1000101,
10101
}
The corresponding method signature will look here:
public long[] toThreeBitCombinations(long l) {
}
(The problem area is poker, listing all the possible card combinations in Omaha Poker's hand. Yes, there are other ways to get close to this, but I am testing this approach, since dealing with bits is much faster than most other alternatives.)