Guest User

Untitled

a guest
Jun 23rd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. from copy import copy
  5.  
  6. _ARG = 'Argentina'
  7. _ICE = 'Islandia'
  8. _NIG = 'Nigeria'
  9. _CRO = 'Croacia'
  10.  
  11. _STANDINGS = {
  12. _ARG: 1,
  13. _ICE: 1,
  14. _NIG: 1,
  15. _CRO: 6,
  16. }
  17.  
  18. _UPCOMING_MATCHES = [
  19. (_NIG, _ICE),
  20. (_NIG, _ARG),
  21. (_ICE, _CRO),
  22. ]
  23.  
  24. def argentina_qualifies(standings):
  25. first = None
  26. second = None
  27. third = None
  28. fourth = None
  29. for team, standing in standings.iteritems():
  30. if not first or standing > first[1]:
  31. fourth = third
  32. third = second
  33. second = first
  34. first = (team, standing)
  35. elif not second or standing > second[1]:
  36. fourth = third
  37. third = second
  38. second = (team, standing)
  39. elif not third or standing > third[1]:
  40. fourth = third
  41. third = (team, standing)
  42. else:
  43. fourth = (team, standing)
  44.  
  45. if _ARG == first[0] or (_ARG == second[0] and second[1] > third[1]):
  46. return 1
  47. elif (_ARG == second[0] or _ARG == third[0]) and third[1] == second[1]:
  48. return 2
  49. elif _ARG == fourth[0] and fourth[1] == third[1] and third[1] == second[1]:
  50. return 2
  51. else:
  52. return 0
  53.  
  54. def match(team1, team2, match_result, remaining_matches, standings, depth):
  55. standings = copy(standings)
  56. if match_result:
  57. standings[match_result] += 3
  58. print ' ' * depth + '{}:{} --> {} gano'.format(team1, team2, match_result)
  59. else:
  60. print ' ' * depth + '{}:{} --> empataron'.format(team1, team2)
  61. standings[team1] +=1
  62. standings[team2] +=1
  63.  
  64. depth += 1
  65.  
  66. if remaining_matches:
  67. play_next(remaining_matches, standings, depth)
  68. else:
  69. arg_score = argentina_qualifies(standings)
  70. if arg_score == 1:
  71. print ' ' * depth + 'Sí! Argentina se califica! {}'.format(standings)
  72. elif arg_score == 2:
  73. print ' ' * depth + 'Quizás, hay que contar goles {}'.format(standings)
  74. else:
  75. print ' ' * depth + 'No {}'.format(standings)
  76.  
  77. def play_next(remaining_matches, standings, depth):
  78. remaining_matches = copy(remaining_matches)
  79. next_match = remaining_matches.pop(0)
  80. match(next_match[0], next_match[1], next_match[0], remaining_matches, standings, depth)
  81. match(next_match[0], next_match[1], None, remaining_matches, standings, depth)
  82. match(next_match[0], next_match[1], next_match[1], remaining_matches, standings, depth)
  83.  
  84. def main():
  85. play_next(_UPCOMING_MATCHES, _STANDINGS, 0)
  86.  
  87. if __name__ == '__main__':
  88. main()
Add Comment
Please, Sign In to add comment