You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
928 B
Python

with open("input") as f:
sues_raw = [n.strip() for n in f.readlines()]
with open("components") as f:
components_raw = [n.strip() for n in f.readlines()]
COMPONENTS = dict()
for component in components_raw:
key, amount = component.split(":")
amount = int(amount)
COMPONENTS[key] = amount
print(COMPONENTS)
SUES = dict()
for sue in sues_raw:
name, component_list = sue.split(":", 1)
component_list = [x.strip() for x in component_list.split(",")]
components = dict()
for component in component_list:
key, amount = component.split(":")
amount = int(amount)
components[key] = amount
SUES[name] = components
def is_match(components):
for key, val in components.items():
if COMPONENTS[key] != val:
return False
return True
print(SUES)
for name, components in SUES.items():
if is_match(components):
print("Found:", name)