Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. from collections import defaultdict
  4.  
  5. GAMES_FILE = 'womens.txt'
  6. WINNER = 'Baylor'
  7.  
  8. # Maps team name to a set of teams they lost to
  9. beat_by = defaultdict(set)
  10.  
  11. # The set of all teams
  12. teams = set()
  13.  
  14. # Read in the game file, grabbing the winner and loser, and adding the winner to
  15. # the set of teams that have beaten the loser, and add both to the list of teams
  16. with open(GAMES_FILE) as games_file:
  17. for game in games_file:
  18. winner = game[12:36].strip()
  19. loser = game[41:64].strip()
  20.  
  21. teams.add(winner)
  22. teams.add(loser)
  23.  
  24. beat_by[loser].add(winner)
  25.  
  26. # Bootstrap the list of teams left to check, and the list of transitive champions
  27. transitive_champs = set([WINNER])
  28. to_check = set([WINNER]) # teams left to check for their victors
  29.  
  30. # While we still have teams to check, take one, add it to the list of transitive
  31. # champions and then add each of the teams that beat it to the list of teams to check (if
  32. # they've not been checked before).
  33. while to_check:
  34. champ = to_check.pop()
  35. transitive_champs.add(champ)
  36. for winner in beat_by[champ]:
  37. if winner not in to_check and winner not in transitive_champs:
  38. to_check.add(winner)
  39.  
  40. print("Teams: {0}".format(len(teams)))
  41. print("Transitive Champs: {0}".format(len(transitive_champs)))
  42. print("Non-Champs: {0}".format(len(teams) - len(transitive_champs)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement