Day 19 (glamorized)
This commit is contained in:
@@ -16,19 +16,18 @@ def yield_rule(line, rule):
|
||||
|
||||
def check(line, idx):
|
||||
rs = rules[idx]
|
||||
if isinstance(rs, str):
|
||||
if line.startswith(rs):
|
||||
yield line[len(rs):]
|
||||
else:
|
||||
if not isinstance(rs, str):
|
||||
for rule in rules[idx]:
|
||||
yield from yield_rule(line, rule)
|
||||
elif line.startswith(rs):
|
||||
yield line[len(rs):]
|
||||
|
||||
|
||||
for line in lines:
|
||||
if ":" in line:
|
||||
idx, r = line.split(": ")
|
||||
idx = int(idx)
|
||||
r = r[1:len(r)-1] if r.startswith('"') else [[int(num) for num in x.split()] for x in r.split(" | ")]
|
||||
r = r[1:len(r)-1] if r.startswith('"') else [list(map(int, x.split())) for x in r.split(" | ")]
|
||||
rules[idx] = r
|
||||
elif line != "":
|
||||
for rest in check(line, 0):
|
||||
|
||||
Reference in New Issue
Block a user