Okay, so i have 52 bits and i need to generate all possible combination of bits, using only n bits at the time. The sequence is not important/duplicates must be avoided ie 1 3 5 and 3 5 1 is the same(as in any bit sequence). any ideas?
It's for a card game simulator.
3 replies to this topic
#1
Posted 20 June 2011 - 06:37 AM
|
|
|
#3
Posted 20 June 2011 - 08:50 AM
Would it be feasible to use Ruby's combination method? Class: Array [ruby-doc.org]
You'll have to do a test to remove repeating values with this method though.
*Edited changed repeat_combination to combination.
You'll have to do a test to remove repeating values with this method though.
*Edited changed repeat_combination to combination.
Edited by lethalwire, 20 June 2011 - 09:30 AM.
#4
Posted 21 June 2011 - 02:47 AM
I found a very useful algorithm from the internet:
Just need to convert it for long type now.
Never mind, i'm reinventing the wheel, java has bitcount built in in the Long class
public static int numberOfSetBits(int i){
i = i - ((i >> 1) & 0x55555555);
i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
return ((i + (i >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
}
No idea how it works, but it's fast as hell. My computer checks every integer for n-bits from 0 to max_integer almost instantly. That's enough for me.Just need to convert it for long type now.
Never mind, i'm reinventing the wheel, java has bitcount built in in the Long class
Edited by Sinipull, 21 June 2011 - 03:50 AM.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









