Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import *
- def rank(x):
- return x%6
- def colour(x):
- return (x/12)
- def suit(x):
- return (x/6)
- def jack(x):
- return (rank(x) == 2)
- def sameSuit(x,y):
- return suit(x) == suit(y)
- def sameColour(x,y):
- return colour(x) == colour(y)
- def s1(H):
- jacks = [0,0]
- non = [0,0,0,0]
- colours = [0,0]
- for h in H:
- if jack(h):
- jacks[colour(h)]+=1
- else:
- non[suit(h)]+=1
- colours[colour(h)]+=1
- if set(jacks) == set([0,2]) and set(non) == set([0,3]) and set(colours) == set([0,5]):
- return True
- return False
- def s2(H,D):
- if s1(H):
- return False
- for h in H:
- # Can we replace h with a card from D and get s1?
- partialHand = H.difference(set([h]))
- for d in D:
- hand = partialHand.union(set([d]))
- if s1(hand):
- return True
- return False
- def s3(H):
- jacks = 0
- for h in H:
- if jack(h):
- jacks += 1
- if jacks == 4:
- return True
- return False
- repeats = 1000000
- for z in range(10):
- s1Count = 0
- s2Count = 0
- s3Count = 0
- for j in range(repeats):
- D = set(range(24))
- h = []
- for i in range(4):
- h.append(set(sample(D, 5)))
- D.difference_update(h[-1])
- got1 = False
- got2 = False
- got3 = False
- #All hands tested per deal
- #for hand in h:
- #One hand tested per deal
- for hand in h[:1]:
- got1 = got1 or s1(hand)
- got2 = got2 or s2(hand, D)
- got3 = got3 or s3(hand)
- if got1:
- s1Count += 1
- if got2:
- s2Count += 1
- if got3:
- s3Count += 1
- print s1Count*100.0/repeats, s2Count*100.0/repeats, s3Count*100.0/repeats
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement