Guest User

Untitled

a guest
Sep 28th, 2013
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. import itertools
  2.  
  3. def matches_outcome(n):
  4.     games =  list(itertools.combinations(range(1, n+1), 2))
  5.     result = []
  6.     for perm in itertools.product(*[(l, l[::-1]) for l in games]):
  7.         result.append(list(perm))
  8.     return result
  9.  
  10. def filter_total(results, n):
  11.     filtered_result = []
  12.     for result in results:
  13.         win_list = []
  14.         loss_list = []
  15.         for outcome in result:
  16.             win_list.append(outcome[0])
  17.             loss_list.append(outcome[1])
  18.         if  win_list.count(max(set(win_list), key=win_list.count)) < n-1 and  loss_list.count(max(set(loss_list), key=loss_list.count)) < n-1:
  19.             filtered_result.append(result)
  20.     return filtered_result
  21.  
  22. def listprint(list):
  23.     for i in list:
  24.         print i
  25.  
  26. # (a,b) means player 'a' played against player 'b' and 'a' won the match.
  27. for i in range(3,6):
  28.     total_outcome = matches_outcome(i)
  29.     no_win_lose = filter_total(total_outcome, i)
  30.     print "total outcome: ",len(total_outcome), " no winner/looser: ", len(no_win_lose)
  31.     listprint(no_win_lose)
Advertisement
Add Comment
Please, Sign In to add comment