Created
September 20, 2012 18:31
-
-
Save cmartello/3757556 to your computer and use it in GitHub Desktop.
"Go First Dice" implemented and tested.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# see : http://www.guardian.co.uk/science/alexs-adventures-in-numberland/2012/sep/18/puzzler-go-first-dice | |
from random import randint, shuffle | |
from itertools import product | |
dice = [[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]] | |
def test(): | |
"""Runs a test to make sure that the dice are fair. a = test() should | |
give : | |
>>> [[a[y].count(x) for x in xrange(0,4)] for y in xrange(1,5)] | |
[ | |
[5184, 5184, 5184, 5184], | |
[5184, 5184, 5184, 5184], | |
[5184, 5184, 5184, 5184], | |
[5184, 5184, 5184, 5184] | |
] | |
""" | |
p = [None,[],[],[],[]] | |
for r in product(dice[0], dice[1], dice[2], dice[3]): | |
z = sorted(zip((1,2,3,4), r), lambda x,y: y[1] - x[1]) | |
for k in xrange(0,4): | |
# p[player].append(turn order) | |
p[z[k][0]].append(k) | |
return p | |
if __name__ == '__main__': | |
p = 1 | |
for x in dice: | |
shuffle(x) | |
print 'player ', p, | |
print x[randint(0,11)] | |
p += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment