I was considering a quick hand assessment in Python. It occurred to me that one way to speed up the process would be to represent all faces of cards and suits as prime numbers and multiply them together to represent hands. For whit:
class PokerCard: faces = '23456789TJQKA' suits = 'cdhs' facePrimes = [11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 53, 59, 61] suitPrimes = [2, 3, 5, 7]
and
def HashVal(self): return PokerCard.facePrimes[self.cardFace] * PokerCard.suitPrimes[self.cardSuit]
This will give each hand a numerical value, which through modulo could tell me how many kings are in the hand or how many hearts. For example, any hand with five or more clubs in it will be divided evenly by 2 ^ 5; any hand with four kings will be evenly divided into 59 ^ 4, etc.
The problem is that a card with seven cards, such as AcAdAhAsKdKhK, has a hash value of about 62.7 quadrillion, which will represent more than 32 bits for presentation within the company. Is there a way to store such large numbers in Python that will allow me to perform arithmetic operations on it?
optimization python largenumber
Yes - that Jake. Feb 11 '09 at 20:13 2009-02-11 20:13
source share