summaryrefslogtreecommitdiffstats
path: root/20/py
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2020-12-16 19:08:58 +0100
committerGustav Sörnäs <gustav@sornas.net>2020-12-16 19:08:58 +0100
commite3372f3dc126a8445c415ed862d441b1277e3fb5 (patch)
tree40af3c6ce5e7f8f620e2dbfb4a4854f537426838 /20/py
parent9e1ce0e8f2d838e652fd592257b3dc3c8fe2fc23 (diff)
downloadaoc-e3372f3dc126a8445c415ed862d441b1277e3fb5.tar.gz
16: actually viable one line
Diffstat (limited to '20/py')
-rw-r--r--20/py/d16.py26
1 files changed, 10 insertions, 16 deletions
diff --git a/20/py/d16.py b/20/py/d16.py
index ed9b224..fb766fe 100644
--- a/20/py/d16.py
+++ b/20/py/d16.py
@@ -20,23 +20,17 @@ def pt1(_in):
def pt2(_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]]
+ constraints = [[range(int((b := a.split("-"))[0]), int(b[1])+1)
+ for a in line.split(": ")[1].split(" or ")]
+ for line in _in[:20]]
- tickets = []
- for line in _in[25:]:
- valid_ticket = True
- for n in line.strip().split(","):
- n = int(n)
- valid_field = False
- for thing in constraints:
- if any(n in r for r in thing):
- valid_field = True
- break
- if not valid_field:
- valid_ticket = False
- break
- if valid_ticket:
- tickets.append(list(int(n) for n in line.strip().split(",")))
+ # all(any(any())) => ALL numbers on a ticket match ANY constraint in ANY constraint group
+ tickets = [[int(n) for n in line.strip().split(",")]
+ for line in _in[25:]
+ if all(any(any(int(n) in cons
+ for cons in constraint)
+ for constraint in constraints)
+ for n in line.strip().split(","))]
# for each field
# assume it can be anything