with open("input") as f: jars = [int(n) for n in f.readlines()] jars.sort(reverse=True) combinations = [] def count_remaining_combinations(remaining_eggnog, remaining_jars, used_jars): if remaining_eggnog == 0: combinations.append(used_jars) return 1 if remaining_eggnog < 0: return 0 if len(remaining_jars) == 0: return 0 count = 0 for idx, jar in enumerate(remaining_jars): count += count_remaining_combinations( remaining_eggnog - jar, remaining_jars[idx + 1 :], used_jars + [jar] ) return count count_remaining_combinations(150, jars, []) minimum_number_of_jars = min([len(x) for x in combinations]) print("Minimum number of jars:", minimum_number_of_jars) minimal_comninations = [x for x in combinations if len(x) == minimum_number_of_jars] print(minimal_comninations) print("Count:") print(len(minimal_comninations))