Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import math
- def distance(points):
- p0, p1 = points
- return math.sqrt((p0[0] - p1[0])**2 + (p0[1] - p1[1])**2)
- trials = 10000
- cards = [{'value':value+1,'suit':suit} for value in range(13) for suit in range(4)]
- counts = [{'total':0, 'count':0} for i in range(len(cards))]
- for i in range(trials):
- start = (0,0)
- location = start
- cardscopy = list(cards)
- random.shuffle(cardscopy)
- for c in range(len(cardscopy)):
- card = cardscopy[c]
- if card['suit'] == 0:
- location = (location[0]+card['value'], location[1])
- elif card['suit'] == 1:
- location = (location[0]-card['value'], location[1])
- elif card['suit'] == 2:
- location = (location[0], location[1]+card['value'])
- else:
- location = (location[0], location[1]-card['value'])
- dist = distance((start,location))
- counts[c]['total'] += dist
- counts[c]['count'] += 1
- for i in range(len(counts)):
- count = counts[i]
- print 'Step %s average distance: %s' % (i+1, count['total'] / count['count'])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement