From e2699eade641e90d879baca7db8a5efbce653784 Mon Sep 17 00:00:00 2001 From: Sebastian Seedorf Date: Wed, 8 Dec 2021 14:25:48 +0100 Subject: [PATCH] Day 05 (minified) --- day05/part2.min.py | 2 ++ day05/part2.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 day05/part2.min.py diff --git a/day05/part2.min.py b/day05/part2.min.py new file mode 100644 index 0000000..acd6c15 --- /dev/null +++ b/day05/part2.min.py @@ -0,0 +1,2 @@ +#!/usr/bin/env python3 +import re;import collections as o;import itertools as i;print(sum(val>=2for val in o.Counter(sum([[*zip(range(a,c+(a<=c)*2-1,(a<=c)*2-1)if a!=c else i.repeat(a),range(b,d+(b<=d)*2-1,(b<=d)*2-1)if b!=d else i.repeat(b))]for[a,b,c,d]in(map(int,re.match(r"(\d+),(\d+) -> (\d+),(\d+)",line).groups())for line in open("input.txt"))],[])).values())) diff --git a/day05/part2.py b/day05/part2.py index 8347f28..a0135e8 100644 --- a/day05/part2.py +++ b/day05/part2.py @@ -9,8 +9,8 @@ points = defaultdict(int) for line in lines: [x1, y1, x2, y2] = list(map(int, re.match(r"(\d+),(\d+) -> (\d+),(\d+)", line).groups())) for x, y in zip( - range(min(x1, x2), max(x1, x2) + 1) if x1 != x2 else repeat(x1), - range(min(y1, y2), max(y1, y2) + 1) if y1 != y2 else repeat(y1) + range(x1, x2+(x1 <= x2)*2-1, (x1 <= x2)*2-1) if x1 != x2 else repeat(x1), + range(y1, y2+(y1 <= y2)*2-1, (y1 <= y2)*2-1) if y1 != y2 else repeat(y1) ): key = '{},{}'.format(x, y) points[key] = points[key] + 1