Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- from copy import copy
- _ARG = 'Argentina'
- _ICE = 'Islandia'
- _NIG = 'Nigeria'
- _CRO = 'Croacia'
- _STANDINGS = {
- _ARG: 1,
- _ICE: 1,
- _NIG: 1,
- _CRO: 6,
- }
- _UPCOMING_MATCHES = [
- (_NIG, _ICE),
- (_NIG, _ARG),
- (_ICE, _CRO),
- ]
- def argentina_qualifies(standings):
- first = None
- second = None
- third = None
- fourth = None
- for team, standing in standings.iteritems():
- if not first or standing > first[1]:
- fourth = third
- third = second
- second = first
- first = (team, standing)
- elif not second or standing > second[1]:
- fourth = third
- third = second
- second = (team, standing)
- elif not third or standing > third[1]:
- fourth = third
- third = (team, standing)
- else:
- fourth = (team, standing)
- if _ARG == first[0] or (_ARG == second[0] and second[1] > third[1]):
- return 1
- elif (_ARG == second[0] or _ARG == third[0]) and third[1] == second[1]:
- return 2
- elif _ARG == fourth[0] and fourth[1] == third[1] and third[1] == second[1]:
- return 2
- else:
- return 0
- def match(team1, team2, match_result, remaining_matches, standings, depth):
- standings = copy(standings)
- if match_result:
- standings[match_result] += 3
- print ' ' * depth + '{}:{} --> {} gano'.format(team1, team2, match_result)
- else:
- print ' ' * depth + '{}:{} --> empataron'.format(team1, team2)
- standings[team1] +=1
- standings[team2] +=1
- depth += 1
- if remaining_matches:
- play_next(remaining_matches, standings, depth)
- else:
- arg_score = argentina_qualifies(standings)
- if arg_score == 1:
- print ' ' * depth + 'Sí! Argentina se califica! {}'.format(standings)
- elif arg_score == 2:
- print ' ' * depth + 'Quizás, hay que contar goles {}'.format(standings)
- else:
- print ' ' * depth + 'No {}'.format(standings)
- def play_next(remaining_matches, standings, depth):
- remaining_matches = copy(remaining_matches)
- next_match = remaining_matches.pop(0)
- match(next_match[0], next_match[1], next_match[0], remaining_matches, standings, depth)
- match(next_match[0], next_match[1], None, remaining_matches, standings, depth)
- match(next_match[0], next_match[1], next_match[1], remaining_matches, standings, depth)
- def main():
- play_next(_UPCOMING_MATCHES, _STANDINGS, 0)
- if __name__ == '__main__':
- main()
Add Comment
Please, Sign In to add comment