1

I know this is a simple question but I am thinking if there is a better way to do so.

I want to calculate the value of a deck of cards. Every card is associated with a number, i.e. there are 1 to 52 cards. I would like to extract the value of a card from a number.

The naive approach would get remainders. For example, 12 = 12 mod 13 or 14 = 1 mod 13.

But it does not work for 13, 26, 39, 52. Is there a simple way to get 13 instead of 0? Thanks in advance.

Rob Arthan
  • 48,577
Www
  • 176
  • 11
  • 1
    I don't understand. Go ahead and number every card $1$ to $52$ if you want. Lots of times people set $2\clubsuit$ to $1$ and $A\spadesuit$ to $52$, but you could assign numbers differently if you prefer. What's the problem? – lulu Sep 21 '21 at 00:28
  • Are you asking: "If we number the cards in the usual way, can we recover the rank from the number in a simple way?" To which, the answer is, as you say, take the remainder (not the reminder) $\pmod {13}$. If you get a $0$, then the card is an Ace. If you get a $12$, the card is a King. And so on. – lulu Sep 21 '21 at 00:32
  • The card is in order. ♣ 1-13 then follow by ♠1-13, etc. Sorry for the confusion – Www Sep 21 '21 at 00:33
  • Using reminder can get the value I want except 13, 26, 39, 52, i.e. the Kings – Www Sep 21 '21 at 00:34
  • 1
    So, you are calling an Ace, $1$? Unusual, but fine. there is still no problem. If you get a $0$, then it is a King. If you get a $12$, it is a Queen, and so on. And, really, the word is "remainder" not "reminder". – lulu Sep 21 '21 at 00:35
  • 3
    If you really want a formula instead of just writing an if-else statement, use ((n-1) mod 13)+1 to yield a number from 1 to 13. – Greg Martin Sep 21 '21 at 00:44
  • Thank you. Greg. This is exactly what I'm looking for. – Www Sep 21 '21 at 00:45
  • lulu. Thanks for the reminder. lol – Www Sep 21 '21 at 00:45
  • This question makes no sense. – David G. Stork Sep 21 '21 at 00:45

0 Answers0