summaryrefslogtreecommitdiffstats
path: root/20
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2020-12-16 18:46:43 +0100
committerGustav Sörnäs <gustav@sornas.net>2020-12-16 18:46:43 +0100
commit489fa5d88ed59b800ec9f33f7a7174b95c2848f0 (patch)
tree4dcb43b1757a26d61e196e6b3635b8fff04c3c0a /20
parentef4f59a33f226e1b1c619a17417c6c7009d9c017 (diff)
downloadaoc-489fa5d88ed59b800ec9f33f7a7174b95c2848f0.tar.gz
16: list comprehensions
Diffstat (limited to '20')
-rw-r--r--20/py/d16.py18
1 files changed, 2 insertions, 16 deletions
diff --git a/20/py/d16.py b/20/py/d16.py
index e9f478b..f6b7f46 100644
--- a/20/py/d16.py
+++ b/20/py/d16.py
@@ -4,14 +4,7 @@ import sys
def pt1(_in):
- things = []
- for line in _in[:20]:
- thing = []
- line = line.strip().split(": ")
- for a in line[1].split(" or "):
- b = a.split("-")
- thing.append(range(int(b[0]), int(b[1])+1))
- things.append(thing)
+ 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(","):
@@ -27,14 +20,7 @@ def pt1(_in):
def pt2(_in):
- constraints = []
- for line in _in[:20]:
- thing = []
- line = line.strip().split(": ")
- for a in line[1].split(" or "):
- b = a.split("-")
- thing.append(range(int(b[0]), int(b[1])+1))
- constraints.append(thing)
+ 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:]: