How to implement a dealer class without storing a deck of cards?

前端 未结 8 1277
长发绾君心
长发绾君心 2021-02-09 19:07
  • Question

    Even only 52 cards, the permutationIndex where I describe in Explanations section, would be a huge number; it is

8条回答
  •  情话喂你
    2021-02-09 19:18

    I am also struggling to see the whole picture here, but you could convert each permutation to base(52) with a single character representing each card and have a string representing each permutation.

    So Spades could be 1-9 (ace - 9), 0ABC (10, J Q K), then DEFG... starting the hearts and so on.

    So a deck of 3 cards, 2 Spade (2), 3 Heart (F) and 2 Diamond (say e), would have these permutation numbers:

    2Fe
    2eF
    F2e
    Fe2
    eF2
    e2F
    

    You could convert these back and forth to a int/long/bigint by doing base 52 to base 10 conversions.

    Here's an introduction to converting between bases.

    So e2F would be F + 2*52 + e * 52^2 which would be 16 + 2*52 + 43*52*52 = 116392

    So 116392 would be your permutation number.

    (btw. I'm guessing about it 2 diamond being 'e' and 43, you can count it up and see exact what it would be)

提交回复
热议问题