day 10 speed tweaks
This commit is contained in:
parent
52313e25ef
commit
2b38e1fc53
27
10/a.py
27
10/a.py
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
|
||||||
|
import sys
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,23 +22,29 @@ class Point(object):
|
||||||
|
|
||||||
def drawpoints(points):
|
def drawpoints(points):
|
||||||
# sort points into rows
|
# sort points into rows
|
||||||
|
minY = sys.maxsize
|
||||||
|
maxY = -minY - 1
|
||||||
|
|
||||||
|
for p in points:
|
||||||
|
if p.y < minY:
|
||||||
|
minY = p.y
|
||||||
|
if p.y > maxY:
|
||||||
|
maxY = p.y
|
||||||
|
|
||||||
|
rangeY = (minY - maxY + 1)
|
||||||
|
|
||||||
|
if abs(rangeY) != 8:
|
||||||
|
return False
|
||||||
|
|
||||||
|
minX = min([i.x for i in points])
|
||||||
|
maxX = max([i.x for i in points])
|
||||||
|
|
||||||
rows = defaultdict(list)
|
rows = defaultdict(list)
|
||||||
for point in points:
|
for point in points:
|
||||||
rows[point.y].append(point)
|
rows[point.y].append(point)
|
||||||
|
|
||||||
minX = min([i.x for i in points])
|
|
||||||
maxX = max([i.x for i in points])
|
|
||||||
minY = min([i.y for i in points])
|
|
||||||
maxY = max([i.y for i in points])
|
|
||||||
|
|
||||||
rangeY = (minY - maxY + 1)
|
|
||||||
|
|
||||||
rows_sorted = sorted(rows.items(), key=lambda x: x[1][0].y)
|
rows_sorted = sorted(rows.items(), key=lambda x: x[1][0].y)
|
||||||
|
|
||||||
if abs(rangeY) != 8:
|
|
||||||
return False
|
|
||||||
|
|
||||||
for rowY, rowpoints in rows_sorted:
|
for rowY, rowpoints in rows_sorted:
|
||||||
rowX = sorted(rowpoints, key=lambda x: x.x)
|
rowX = sorted(rowpoints, key=lambda x: x.x)
|
||||||
for i in range(minX, maxX + 1):
|
for i in range(minX, maxX + 1):
|
||||||
|
|
Loading…
Reference in New Issue