Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- from collections import defaultdict
- GAMES_FILE = 'womens.txt'
- WINNER = 'Baylor'
- # Maps team name to a set of teams they lost to
- beat_by = defaultdict(set)
- # The set of all teams
- teams = set()
- # Read in the game file, grabbing the winner and loser, and adding the winner to
- # the set of teams that have beaten the loser, and add both to the list of teams
- with open(GAMES_FILE) as games_file:
- for game in games_file:
- winner = game[12:36].strip()
- loser = game[41:64].strip()
- teams.add(winner)
- teams.add(loser)
- beat_by[loser].add(winner)
- # Bootstrap the list of teams left to check, and the list of transitive champions
- transitive_champs = set([WINNER])
- to_check = set([WINNER]) # teams left to check for their victors
- # While we still have teams to check, take one, add it to the list of transitive
- # champions and then add each of the teams that beat it to the list of teams to check (if
- # they've not been checked before).
- while to_check:
- champ = to_check.pop()
- transitive_champs.add(champ)
- for winner in beat_by[champ]:
- if winner not in to_check and winner not in transitive_champs:
- to_check.add(winner)
- print("Teams: {0}".format(len(teams)))
- print("Transitive Champs: {0}".format(len(transitive_champs)))
- print("Non-Champs: {0}".format(len(teams) - len(transitive_champs)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement