diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2020-12-16 19:10:37 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2020-12-16 19:10:37 +0100 |
| commit | 1707bb001f24330dbe67b11e6ed665ad5054745d (patch) | |
| tree | d496fe428ea0a5cecbdb7b4a1f7040ced4993dc6 | |
| parent | e3372f3dc126a8445c415ed862d441b1277e3fb5 (diff) | |
| download | aoc-1707bb001f24330dbe67b11e6ed665ad5054745d.tar.gz | |
16: oneline part 1
| -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): |
