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.
48 lines
1.2 KiB
Python
48 lines
1.2 KiB
Python
3 years ago
|
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, remembered_val in components.items():
|
||
|
measured_val = COMPONENTS[key]
|
||
|
if key in ["cats", "trees"]:
|
||
|
if not remembered_val > measured_val:
|
||
|
return False
|
||
|
elif key in ["pomeranians", "goldfish"]:
|
||
|
if not remembered_val < measured_val:
|
||
|
return False
|
||
|
elif remembered_val != measured_val:
|
||
|
return False
|
||
|
return True
|
||
|
|
||
|
|
||
|
for name, components in SUES.items():
|
||
|
if is_match(components):
|
||
|
print("Found:", name)
|
||
|
|
||
|
print("Finish")
|