Skip to content

Instantly share code, notes, and snippets.

@sushain97
Created April 16, 2017 19:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sushain97/386239a51fc8bba95b8b0c4a20d9afd9 to your computer and use it in GitHub Desktop.
Save sushain97/386239a51fc8bba95b8b0c4a20d9afd9 to your computer and use it in GitHub Desktop.
def min_hitting_set(students):
def help(students, tests):
students = sorted(list(filter(lambda s: s and not (s & tests), students)), key=set.__len__)
if students:
student, *students = students
return min(map(lambda t: help(students, set([t]) | tests), student), key=set.__len__)
return tests
return help(students, set())
if __name__ == '__main__':
print(min_hitting_set(students))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment