diff options
| -rw-r--r-- | 20/py/d16.py | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/20/py/d16.py b/20/py/d16.py index fb766fe..09a7c9c 100644 --- a/20/py/d16.py +++ b/20/py/d16.py @@ -4,19 +4,15 @@ import sys def pt1(_in): - constraints = [[range(int((b := a.split("-"))[0]), int(b[1])+1) for a in line.split(": ")[1].split(" or ")] for line in _in[:20]] - res = 0 - for line in _in[25:]: - for n in line.strip().split(","): - n = int(n) - valid = False - for thing in things: - if any(n in r for r in thing): - valid = True - break - if not valid: - res += n - return res + constraints = [[range(int((b := a.split("-"))[0]), int(b[1])+1) + for a in line.split(": ")[1].split(" or ")] + for line in _in[:20]] + return sum(sum(int(field) + for field in line.strip().split(",") + if not any(any(int(field) in cons + for cons in constraint) + for constraint in constraints)) + for line in _in[25:]) def pt2(_in): |
