Advertisement
Guest User

Untitled

a guest
Jul 31st, 2018
47
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from typing import Set, List
  2.  
  3.  
  4. class Term(int):
  5.     def is_better_than(self, other):
  6.         return self // 2 > other // 2
  7.  
  8.  
  9. def get_best_terms(terms: Set[Term]) -> List[Term]:
  10.     terms = iter(terms)
  11.     max = next(terms)
  12.     equal = {max}
  13.     for term in terms:
  14.         if term.is_better_than(max):
  15.             max = term
  16.             equal = {max}
  17.         elif not max.is_better_than(term):
  18.             equal.add(term)
  19.     return equal
  20.  
  21.  
  22. print(get_best_terms(map(Term, [1, 2, 3, 4, 5])))
  23. print(get_best_terms(map(Term, [1, 2, 3, 4])))
  24. print(get_best_terms(map(Term, [5, 1, 2, 4, 3])))
  25. print(get_best_terms(map(Term, [5, 1, 4, 3])))
Advertisement
RAW Paste Data Copied
Advertisement