This is such an obscure problem that I suspect I'll have to do it at a different level in my code...but hopefully the hive mind that is Stack Overflow can help...
I have a long, which if expressed as a binary string will have exactly five bits set. For example,
long l = 341; // as a bit string, "101010101"
I'm seeking an array containing all ten possible longs which exactly three of those bits set. To continue the example,
long[] results = {
101010000,
101000100,
101000001,
100010100,
100010001,
100000101,
1010100,
1010001,
1000101,
10101
}
Here's what the appropriate method signature might look like:
public long[] toThreeBitCombinations(long l) {
// what goes here?
}
(The problem domain is poker; enumerating all the possible board card combinations in a Omaha Poker hand. Yep, there are other ways to approach this, but I am testing out this approach, as dealing with bits is so much quicker than most other alternatives.)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…