From 1707bb001f24330dbe67b11e6ed665ad5054745d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Wed, 16 Dec 2020 19:10:37 +0100 Subject: 16: oneline part 1 --- 20/py/d16.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to '20/py/d16.py') 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): -- cgit v1.2.1