Day 05 (minified)
This commit is contained in:
2
day05/part2.min.py
Normal file
2
day05/part2.min.py
Normal file
@@ -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()))
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user