Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import itertools
- def matches_outcome(n):
- games = list(itertools.combinations(range(1, n+1), 2))
- result = []
- for perm in itertools.product(*[(l, l[::-1]) for l in games]):
- result.append(list(perm))
- return result
- def filter_total(results, n):
- filtered_result = []
- for result in results:
- win_list = []
- loss_list = []
- for outcome in result:
- win_list.append(outcome[0])
- loss_list.append(outcome[1])
- 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:
- filtered_result.append(result)
- return filtered_result
- def listprint(list):
- for i in list:
- print i
- # (a,b) means player 'a' played against player 'b' and 'a' won the match.
- for i in range(3,6):
- total_outcome = matches_outcome(i)
- no_win_lose = filter_total(total_outcome, i)
- print "total outcome: ",len(total_outcome), " no winner/looser: ", len(no_win_lose)
- listprint(no_win_lose)
Advertisement
Add Comment
Please, Sign In to add comment