Created
April 16, 2017 19:55
-
-
Save sushain97/386239a51fc8bba95b8b0c4a20d9afd9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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