Difficulty - Hard
Actually stick to getting on with some coding / learning rather then browsing the net / watching tv / playing games ect.
Yoriz wrote:That looks quite acurate apart from the 20% figuring out yesterdays code when its quite likely that you didnt actually manage to write any code yesterday, you put it off for the next day.
import itertools
def has_subset_sum(seq, n=0):
all_subsets = (itertools.combinations(seq, i) for i in range(1, len(seq)+1))
return n in (sum(subset) for subsets in all_subsets for subset in subsets)
if __name__ == "__main__":
test_sequence = {-7, 22, -3, -2, 17, 4, -39}
print(has_subset_sum(test_sequence))
Users browsing this forum: No registered users and 2 guests