-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpartOne.py
More file actions
28 lines (19 loc) · 694 Bytes
/
Copy pathpartOne.py
File metadata and controls
28 lines (19 loc) · 694 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from common import *
from typing import Dict
def check_bag(ruleset: Dict[str, Dict[str, int]], test_cl: str, target_cl: str) -> bool:
if (
target_cl in ruleset[test_cl]
): # bag colour can directly contain the target colour
return True
for child_colours in ruleset[test_cl]:
if check_bag(ruleset, child_colours, target_cl):
return True
return False
def partOne(instr: str) -> int:
rules = parse(instr)
can_contain_target = 0
for bag_colour in rules:
if bag_colour != target_colour:
if check_bag(rules, bag_colour, target_colour):
can_contain_target += 1
return can_contain_target