COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### combo numbering

• Email
• Follow

```If you have 52 cards and you choose 7, there are 133,784,560
possibilities.

So, let's say you have 7 playing cards. Is there an easy way to convert
these cards into a number between 0 and 133,784,559?

```
 0
Reply bob136 (434) 10/6/2005 7:22:58 PM

See related articles to this posting

```bob@coolgroups.com wrote:
> If you have 52 cards and you choose 7, there are 133,784,560
> possibilities.
>
> So, let's say you have 7 playing cards. Is there an easy way to convert
> these cards into a number between 0 and 133,784,559?

consider a 52bit number.
bit position 0 is ace of spades
bit position 1 is duece of spades
bit position 2 is 3 of spades ... etc.

the 7card hand is a 52bit number with seven 1 bits.

You could also use four 13bit numbers , one per suit.
that's easily just 4 ints.

HTH,
ed

```
 0
Reply ed.prochak (222) 10/6/2005 9:12:46 PM

```A 52bit number has 4.50359963 =D7 10^15 possibilities, which is way too
high.  I'm planning on storing an array of 133,784,560 32 bit numbers
in memory, which takes up about 600 mb.  This is on a machine that has
only 768 MB of RAM.

Ed Prochak wrote:
> bob@coolgroups.com wrote:
> > If you have 52 cards and you choose 7, there are 133,784,560
> > possibilities.
> >
> > So, let's say you have 7 playing cards. Is there an easy way to convert
> > these cards into a number between 0 and 133,784,559?
>
> consider a 52bit number.
> bit position 0 is ace of spades
> bit position 1 is duece of spades
> bit position 2 is 3 of spades ... etc.
>
> the 7card hand is a 52bit number with seven 1 bits.
>
> You could also use four 13bit numbers , one per suit.
> that's easily just 4 ints.
>=20
> HTH,
>   ed

```
 0
Reply bob136 (434) 10/6/2005 9:28:12 PM

```<bob@coolgroups.com> wrote in message
>A 52bit number has 4.50359963 � 10^15 possibilities, which is way too
>high.  I'm planning on storing an array of 133,784,560 32 bit numbers
>in memory, which takes up about 600 mb.  This is on a machine that has
>only 768 MB of RAM.

You have 52 cards, so you have to use 6 bits (0..63) to identify each card
(0..12 per card, 2 bits for its color).
7 cards use 42 bits -> 5 1/4 byte.
I don't think there is any way to store information about 52 elements in
just one 32 bit number! Your 133 mil combinations will therefore need 133
mil times 5 1/4 bytes of information, thats already 700 MB.
Actually, first thing I though would be to loose the 1/4 byte and expand to
6 bytes; then, a natural optimization would be to use 8 bytes and lo and
behold... you're out of memory.
How did you arrive on 133 mil? 52*51*50*49*48*47*46 = 674,274,182,400.

[jongware]

```
 0
Reply jongware2 (81) 10/6/2005 10:10:29 PM

```[jongware] wrote:
> <bob@coolgroups.com> wrote in message
> >A 52bit number has 4.50359963 =D7 10^15 possibilities, which is way too
> >high.  I'm planning on storing an array of 133,784,560 32 bit numbers
> >in memory, which takes up about 600 mb.  This is on a machine that has
> >only 768 MB of RAM.
>
> You have 52 cards, so you have to use 6 bits (0..63) to identify each card
> (0..12 per card, 2 bits for its color).
> 7 cards use 42 bits -> 5 1/4 byte.
> I don't think there is any way to store information about 52 elements in
> just one 32 bit number! Your 133 mil combinations will therefore need 133
> mil times 5 1/4 bytes of information, thats already 700 MB.
> Actually, first thing I though would be to loose the 1/4 byte and expand =
to
> 6 bytes; then, a natural optimization would be to use 8 bytes and lo and
> behold... you're out of memory.
> How did you arrive on 133 mil? 52*51*50*49*48*47*46 =3D 674,274,182,400.

That's permutations (order significant). Divide that by 7*6*5*4*3*2
to get combinations (order insignificant).

>=20
> [jongware]

```
 0

```bob@coolgroups.com wrote:

> If you have 52 cards and you choose 7, there are 133,784,560
> possibilities.
>
> So, let's say you have 7 playing cards. Is there an easy way to convert
> these cards into a number between 0 and 133,784,559?

I wrote a set of C functions a while ago to convert from a combination
index to the combination, and the reverse.  It has a lot more than you
would need for this, but you are welcome to use it.

The added complexity comes from allowing sets with some identical items
and setting a maximum of the number of identical items in a combination.
It also has code to detect arithmetic overflow in computing the index.

The header file describes the interface.  If you define TEST then the
code will compile a test program to allow you to convert back and forth.

```
 0

```<bob@coolgroups.com> wrote in message
> If you have 52 cards and you choose 7, there are 133,784,560
> possibilities.
>
> So, let's say you have 7 playing cards. Is there an easy way to convert
> these cards into a number between 0 and 133,784,559?
>

http://www.gnu.org/software/gsl/manual/gsl-ref_10.html

```
 0
Reply rkww (343) 10/7/2005 8:25:46 AM

```Please don't top post.

bob@coolgroups.com wrote:
> A 52bit number has 4.50359963 =D7 10^15 possibilities, which is way too
> high.  I'm planning on storing an array of 133,784,560 32 bit numbers
> in memory, which takes up about 600 mb.  This is on a machine that has
> only 768 MB of RAM.
>
>
> Ed Prochak wrote:
> > bob@coolgroups.com wrote:
> > > If you have 52 cards and you choose 7, there are 133,784,560
> > > possibilities.
> > >
> > > So, let's say you have 7 playing cards. Is there an easy way to conve=
rt
> > > these cards into a number between 0 and 133,784,559?
> >
> > consider a 52bit number.
> > bit position 0 is ace of spades
> > bit position 1 is duece of spades
> > bit position 2 is 3 of spades ... etc.
> >
> > the 7card hand is a 52bit number with seven 1 bits.
> >
> > You could also use four 13bit numbers , one per suit.
> > that's easily just 4 ints.
> >
> > HTH,
> >   ed

You asked for a way to map from the list of 7 cards to a number, IS a
HASH function. I gave you one. The fact that the hash function uses
52bit numbers does not require you to store ALL possible hash values. I
simply gave you a way to go from a list of 7cards to a number, or given
the number to go back to the list of cards. If you are storing ONLY the
sets of seven cards, then the only values you will use are numbers that
have seven bits one and all the rest are zeroes.

The 52bit map can actually represent any combination of any number
cards. From a value of zero representing NO cards selected. to the MAX
value which represents ALL the cards in the deck. and where 1 is say
the ACE of spades, 2 is the duece of spades, which means 3 is BOTH the
ace and duece of spades are selected (ie two cards in you hand).

I did not say this was the best. Depends on you application. It was
just one suggestion. Just understand it properly befor you dismiss it.

HTH,
Ed

```
 0
Reply ed.prochak (222) 10/10/2005 5:27:47 AM

7 Replies
39 Views

Similar Articles

12/6/2013 2:31:22 PM
page loaded in 103816 ms. (0)