def calculate_score(data): gold, silver = data.get('gold', 0), data.get('silver', 0) moved = data.get('moved', False) token_score = 2*(gold + silver) // (2 if gold and silver else 1) return token_score + int(moved) def calculate_scores(scores): return {tla: calculate_score(data) for tla, data in scores.iteritems()} if __name__ == '__main__': import sys sys.path.append('libproton') import libproton libproton.main(calculate_scores)
if backs == 0 else (backs - 1, cans, score), 'u': can_up, 'd': can_down, 'END': lambda backs, cans, score: (backs, cans, score + (cans * CAN_END_POINTS)), } events = list(events.lower()) + ['END'] backs, cans, score = 0, 0, 0 for event in events: if event.isspace(): continue backs, cans, score = event_handlers[event](backs, cans, score) if holding_super and cans == 0: raise InvalidScoresheetException( "Cannot be holding the super can -- not holding any cans at the end", ) return score if __name__ == '__main__': import libproton libproton.main(Scorer)
#!/usr/bin/env python import os import sys path = os.path.dirname(os.path.realpath(__file__)) + "/lib/" sys.path.insert(0, path) from scorer import Scorer path = os.path.join(path, "libproton/") sys.path.insert(0, path) import libproton def score(teams_data): return Scorer(teams_data).calculate_scores() libproton.main(score)
#!/usr/bin/env python from os.path import dirname, realpath import sys path = dirname(dirname(dirname(dirname(realpath(__file__))))) sys.path.insert(0, path) import libproton def scorer(teams_data): scores = {} for tla, value in teams_data.items(): # Double the bacon and add 5, for fun scores[tla] = 5 + 2*value['bacon'] return scores libproton.main(scorer)
#!/usr/bin/env python import os import sys path = os.path.dirname(os.path.realpath(__file__)) + "/lib/" sys.path.insert(0, path) from scorer import Scorer path = os.path.join(path, "libproton/") sys.path.insert(0, path) import libproton def score(teams_data): return Scorer(teams_data).calculate_scores() libproton.main(score)
#!/usr/bin/env python from os.path import dirname, realpath import sys path = dirname(dirname(dirname(dirname(realpath(__file__))))) sys.path.insert(0, path) import libproton class Scorer: def __init__(self, teams_data, arena_data): self._teams_data = teams_data def calculate_scores(self): scores = {} for tla, value in self._teams_data.items(): # Double the bacon and add 5, for fun scores[tla] = 5 + 2*value['bacon'] return scores def validate(self, extra_data): assert extra_data == 42 or extra_data is None, \ "Optional extra should be 42 if present" if __name__ == '__main__': libproton.main(Scorer)
#!/usr/bin/env python from os.path import dirname, realpath import sys path = dirname(dirname(dirname(dirname(realpath(__file__))))) sys.path.insert(0, path) import libproton def scorer(teams_data): scores = {} for tla, value in teams_data.items(): # Double the bacon and add 5, for fun scores[tla] = 5 + 2 * value['bacon'] return scores libproton.main(scorer)