Day 19 (cleanup)
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import re
|
|
||||||
|
|
||||||
lines = (x.strip() for x in open("input.txt"))
|
lines = (x.strip() for x in open("input.txt"))
|
||||||
rules = {}
|
rules = {}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import re
|
|
||||||
|
|
||||||
lines = (x.strip() for x in open("input.txt"))
|
lines = (x.strip() for x in open("input.txt"))
|
||||||
rules = {}
|
rules = {}
|
||||||
@@ -15,19 +14,20 @@ def yield_rule(line, rule, depth):
|
|||||||
|
|
||||||
|
|
||||||
def check(line, idx, depth=0):
|
def check(line, idx, depth=0):
|
||||||
if depth <= 100:
|
if depth > 100:
|
||||||
rs = rules[idx]
|
return
|
||||||
if isinstance(rs, str):
|
rs = rules[idx]
|
||||||
if line.startswith(rs):
|
if isinstance(rs, str):
|
||||||
yield line[len(rs):]
|
if line.startswith(rs):
|
||||||
else:
|
yield line[len(rs):]
|
||||||
for rule in rules[idx]:
|
else:
|
||||||
yield from yield_rule(line, rule, depth)
|
for rule in rules[idx]:
|
||||||
|
yield from yield_rule(line, rule, depth)
|
||||||
|
|
||||||
|
|
||||||
sum = 0
|
sum = 0
|
||||||
for line in lines:
|
for line in lines:
|
||||||
line = '11: 42 31 | 42 11 31' if line.startswith('11: ') else line
|
line = '11: 42 31 | 42 11 31' if line.startswith('11:') else line
|
||||||
line = '8: 42 | 42 8' if line.startswith('8:') else line
|
line = '8: 42 | 42 8' if line.startswith('8:') else line
|
||||||
if ":" in line:
|
if ":" in line:
|
||||||
idx, r = line.split(": ")
|
idx, r = line.split(": ")
|
||||||
|
|||||||
Reference in New Issue
Block a user