Generating all 5 card poker hands

前端 未结 11 688
再見小時候
再見小時候 2020-12-23 09:53

This problem sounds simple at first glance, but turns out to be a lot more complicated than it seems. It\'s got me stumped for the moment.

There are 52c5 = 2,598,960

11条回答
  •  余生分开走
    2020-12-23 10:31

    You could simply give all hands a canonical ordering of values (A to K), then assign abstract suit letters according to their order of first appearance in that order.

    Example: JH 4C QD 9C 3D would convert to 3a 4b 9b Jc Qa.

    Generation should work best as dynamic programming:

    • start with a set of a single hand that is empty,
    • make a new set:
      • for each hand in the old set, generate each possible hand by adding one of the remaining cards
      • canonicalize all new hands
      • remove duplicates

提交回复
热议问题