Subj : Re: combo numbering To : comp.programming From : Ed Prochak Date : Sun Oct 09 2005 11:27 pm 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 .