Background
As described here http://www.ericharshbarger.org/dice/#gofirst_4d12, "Go First" Dice is a set of four dice, each with unique numbering, so that:
- There will never be a tie. Each die has a unique set of numbers.
- Regardless of what subset of dice are rolled against one another, each player will always have an equal chance of rolling the high number.
Here is the specific numbering for the four dice mentioned, as an example:
DICE COUNT: 4
FACE COUNT: 12
D1: 1,8,11,14,19,22,27,30,35,38,41,48
D2: 2,7,10,15,18,23,26,31,34,39,42,47
D3: 3,6,12,13,17,24,25,32,36,37,43,46
D4: 4,5, 9,16,20,21,28,29,33,40,44,45
Goal
Without requiring any particular result, I would like to be able to generate a set of N "Go First" dice... Such that, example output might look like so (formatted, python console):
>>> generate_dice(players=4)
[[1,8,11,14,19,22,27,30,35,38,41,48],
[2,7,10,15,18,23,26,31,34,39,42,47],
[3,6,12,13,17,24,25,32,36,37,43,46],
[4,5,9,16,20,21,28,29,33,40,44,45]]
The number of sides here is chosen just for example purposes, because it matches the other example given. The number of sides of the dice can be determined by the algorithm used.
Ideally the solution would be in Python, but I can also read PHP, Javascript, some Ruby, quite well.
I'm honestly puzzling over this, and would love to understand what terminology/math I should have studied to figure this out. I've tried to explain it before, but seem to be having trouble not using words that imply too many things about what should be generated, and what odds should be, etc. I'm specifically interested in being able to generate "a set of N 'Go First' dice".
Extra
Here's some ugly python, to "prove" the dice, and perhaps give an example.
def fair_chance(die1, die2):
wins = 0
losses = 0
ties = 0
for i in die1:
for x in die2:
if cmp(i, x) < 0:
losses += 1
if cmp(i, x) > 0:
wins += 1
if cmp(i, x) == 0:
ties += 1
if wins == losses and losses != 0 and ties == 0:
return True
return False
Give the above example dice:
D1 = [1,8,11,14,19,22,27,30,35,38,41,48]
D2 = [2,7,10,15,18,23,26,31,34,39,42,47]
D3 = [3,6,12,13,17,24,25,32,36,37,43,46]
D4 = [4,5, 9,16,20,21,28,29,33,40,44,45]
fair_chance(D1, D2) # True
fair_chance(D1, D3) # True
fair_chance(D1, D4) # True
fair_chance(D2, D3) # True
fair_chance(D2, D4) # True
fair_chance(D3, D4) # True
Thus, the function generate_dice should work, such that output in a Python shell would look like this:
>>> dice = generate_dice(players=4)
>>> D1 = dice[0]
>>> D2 = dice[1]
>>> D3 = dice[2]
>>> D4 = dice[3]
>>> fair_chance(D1, D2)
True
>>> fair_chance(D1, D3)
True
>>> fair_chance(D1, D4)
True
>>> fair_chance(D2, D3)
True
>>> fair_chance(D2, D4)
True
>>> fair_chance(D3, D4)
True
Ndice each havingDsides and we want a fair result for any1 < M <= Nsubset, we requireD^M == 0 (mod M). ThereforeDmust be a multiple of theNth primorial number. – Peter Taylor Sep 20 '12 at 20:36