Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import shuffle
- players = 'icy jeff dij yoma omsi dig klu'.split()
- totals = [712,614,595,475,259,145,157]
- items = 'voodoo hodgman extra jar frosty ol'.split()
- values = [9,55,27,67,30,22]
- counts = [15,11,16,15,15,15]
- nitems = len(items)
- nplayers = len(players)
- mindefect = sum(totals)
- print 'total value owed to players', sum(totals)
- print 'total value of goods', sum(a*b for a,b in zip(values,counts))
- for trial in range(100000):
- tots = totals[:]
- dist_val = [0]*nplayers
- dist_items = [[0]*nitems for p in range(nplayers)]
- indices = [x for x in range(nitems) for i in range(counts[x])]
- shuffle(indices)
- for i in indices:
- maxtot = max(tots)
- p = tots.index(maxtot)
- dist_items[p][i]+=1
- tots[p]-= values[i]
- defect = max(map(abs,tots))
- if defect < mindefect:
- mindefect = defect
- distribution = dist_items
- print 'maximum error in distribution', mindefect
- for i,p in enumerate(players):
- print p, 'gets', ', '.join(`d`+' '+x for x,d in zip(items,distribution[i]))
- print
- print
- print 'paste this into the spreadsheet'
- for i in range(nitems):
- c = values[i]
- print '\t'.join(`c*d[i]` for d in distribution)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement