Advertisement
Guest User

Untitled

a guest
Jul 17th, 2014
436
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.22 KB | None | 0 0
  1. from random import shuffle
  2.  
  3. players = 'icy jeff dij yoma omsi dig klu'.split()
  4. totals = [712,614,595,475,259,145,157]
  5. items = 'voodoo hodgman extra jar frosty ol'.split()
  6. values = [9,55,27,67,30,22]
  7. counts = [15,11,16,15,15,15]
  8.  
  9. nitems = len(items)
  10. nplayers = len(players)
  11.  
  12. mindefect = sum(totals)
  13.  
  14. print 'total value owed to players', sum(totals)
  15. print 'total value of goods', sum(a*b for a,b in zip(values,counts))
  16.  
  17. for trial in range(100000):
  18.     tots = totals[:]
  19.     dist_val = [0]*nplayers
  20.     dist_items = [[0]*nitems for p in range(nplayers)]
  21.     indices = [x for x in range(nitems) for i in range(counts[x])]
  22.     shuffle(indices)
  23.     for i in indices:
  24.          maxtot = max(tots)
  25.          p = tots.index(maxtot)
  26.          dist_items[p][i]+=1
  27.          tots[p]-= values[i]
  28.     defect = max(map(abs,tots))
  29.     if defect < mindefect:
  30.         mindefect = defect
  31.         distribution = dist_items
  32.  
  33. print 'maximum error in distribution', mindefect
  34. for i,p in enumerate(players):
  35.     print p, 'gets', ', '.join(`d`+' '+x for x,d in zip(items,distribution[i]))
  36.  
  37. print
  38. print
  39. print 'paste this into the spreadsheet'
  40. for i in range(nitems):
  41.     c = values[i]
  42.     print '\t'.join(`c*d[i]` for d in distribution)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement