Day 17: No such thing as too much


In [ ]:
containers = [50, 44, 11, 49, 42, 46, 18, 32, 26, 40, 21, 7, 18, 43, 10, 47, 36, 24, 22, 40]

Day 17.1


In [2]:
from sympy.abc import x
from sympy import Poly

In [8]:
def combine(total, containers):
    poly = 1
    for i in containers:
        poly *= (1 + x**i)
    poly = Poly(poly)
    return poly.all_coeffs()[total]

In [9]:
combine(150, containers)


Out[9]:
654

Day 17.2


In [10]:
from sympy.abc import x, y

In [24]:
def min_combine(total, containers):
    poly = 1
    for i in containers:
        poly *= (y + x**i)
    poly = Poly(poly)
    coeff_dict = dict(zip(poly.monoms(), poly.coeffs()))
    master_monom = sorted([m for m in poly.monoms() if m[0] == total], key=lambda a: a[1], reverse=True)[0]
    return coeff_dict[master_monom]

In [25]:
min_combine(150, containers)


Out[25]:
57