My Advent of Code solutions in Python. kevinyap.ca/2019/12/going-fast-in-advent-of-code/
advent-of-code python
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 21 lines 644 B view raw
1import fileinput 2import itertools 3import re 4 5LITRES = 150 6 7def permute_containers(containers, litres): 8 for i in range(1, len(containers) + 1): 9 for c in itertools.combinations(containers, i): 10 if sum(c) == litres: 11 yield c 12 13containers = [int(n) for n in fileinput.input()] 14permutations = list(permute_containers(containers, LITRES)) 15min_perm_len = min(len(p) for p in permutations) 16 17print "Containers: {}".format(containers) 18print "Litres of eggnog: %d" % LITRES 19 20print "Valid combinations: %d" % len(permutations) 21print "Minimal combinations: %d" % len([p for p in permutations if len(p) == min_perm_len])