Advertisement
gasbaitlad

Untitled

Jul 15th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.19 KB | None | 0 0
  1. import itertools
  2. import csv
  3.  
  4. def comb1(k, available, used):
  5.     if len(used)==k: #hits the required number of units in a combo
  6.         yield tuple(used)
  7.     elif len(available)==0: # went through all avaliable and has none left over
  8.         pass
  9.     else:
  10.         head=available.pop(0)
  11.         used.append(head)
  12.         for c in comb1(k, available[:], used[:]):
  13.             yield c
  14.         used.pop()
  15.         for c in comb1(k, available[:], used[:]):
  16.             yield c
  17.  
  18. n=50000
  19. n2=49500
  20.  
  21. def comb_wrapper(k,s,n,n2):
  22.     for c in comb1(k,list(s),[]):
  23.         total= sum(s[i]['cost'] for i in c)
  24.         if list(filter(lambda player_name: s[player_name]["Opponent"] in c, c)):
  25.             continue
  26.         if n >= total >= n2:
  27.             yield c
  28.  
  29.  
  30.  
  31. s={'Mike Rodriguez': {'cost': 9400, 'Opponent': 'John Allan'}, 'Ricky Simon': {'cost': 9300, 'Opponent': 'Urijah Faber'}, 'Karl Roberson': {'cost': 9100, 'Opponent': 'Wellington Turman'}, 'Julianna Pena': {'cost': 9000, 'Opponent': 'Nicco Montano'}, 'Aspen Ladd': {'cost': 8900, 'Opponent': 'Germaine de Randamie'}, 'Mirsad Bektic': {'cost': 8800, 'Opponent': 'Josh Emmett'}, 'Liu Pingyuan': {'cost': 8700, 'Opponent': 'Jonathan Martinez'}, 'Marvin Vettori': {'cost': 8600, 'Opponent': 'Cezar Ferreira'}, 'Vince Morales': {'cost': 8500, 'Opponent': 'Benito Lopez'}, 'Sheymon Moraes': {'cost': 8400, 'Opponent': 'Andre Fili'}, 'Ryan Hall': {'cost': 8300, 'Opponent': 'Darren Elkins'}, 'Brianna Van Buren': {'cost': 8200, 'Opponent': 'Livinha Souza'}, 'Livinha Souza': {'cost': 8000, 'Opponent': 'Brianna Van Buren'}, 'Darren Elkins': {'cost': 7900, 'Opponent': 'Ryan Hall'}, 'Andre Fili': {'cost': 7800, 'Opponent': 'Sheymon Moraes'}, 'Benito Lopez': {'cost': 7700, 'Opponent': 'Vince Morales'}, 'Cezar Ferreira': {'cost': 7600, 'Opponent': 'Marvin Vettori'}, 'Jonathan Martinez': {'cost': 7500, 'Opponent': 'Liu Pingyuan'}, 'Josh Emmett': {'cost': 7400, 'Opponent': 'Mirsad Bektic'}, 'Germaine de Randamie': {'cost': 7300, 'Opponent': 'Aspen Ladd'}, 'Nicco Montano': {'cost': 7200, 'Opponent': 'Julianna Pena'}, 'Wellington Turman': {'cost': 7100, 'Opponent': 'Karl Roberson'}, 'Urijah Faber': {'cost': 6900, 'Opponent': 'Ricky Simon'}, 'John Allan': {'cost': 6800, 'Opponent': 'Mike Rodriguez'}}
  32.  
  33. k=6
  34.  
  35.  
  36.  
  37.  
  38. mycombs=list(comb_wrapper(k, s, n, n2))
  39. print(len(mycombs))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement