0

So to demonstrate what I'm hoping to achieve I'll use a deck of cards.

Let's say there are three people, each with their own randomly shuffled deck. The cards in the deck simply have values 1 through 13, and there are four of each card.

When it comes time to draw a card, everyone takes their top card and shows its value to the other two players.

What I want now, is some way to map the values of each of these top cards to a single integer from 1 - 13. The goal being that this algorithm would generate something unique for each operation, and only allow for 4 of the same value (when the exact same inputs are calculated each of 4 times it can happen).

I know I can use Cantor Pairing Function to generate a unique value, but again I want it to be in the range 1-13.

bafrick
  • 17
  • 5
  • You're not exactly mapping n integers to a value within [1, N] here. It's more like you're mapping n C 4 integers to a value within [1, N]. Hashing functions will get you there, but at the cost of no guarantee of uniqueness. – AndyG Jul 01 '16 at 17:13
  • @AndyG Good point, I altered my question title to be more accurate. As for using hashing functions, my backup plan is to just do that and deal with collisions normally, but I still want uniqueness if it's algorithmically possible. – bafrick Jul 01 '16 at 17:15

1 Answers1

0

The Cantor pairing function is only necessary if you want to map all positive integers. What's wrong with simply the following, with n = 13 and N = n^4?

(val1 - 1) * n^3 + (val2 - 1) * n^2 + (val3 - 1) * n + (val4 - 1) + 1

The ordering can be given by the suit of the card, or the order in which they are drawn.

Cimbali
  • 11,012
  • 1
  • 39
  • 68