Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
distinct lines solution in Clear category for The Rows of Cakes by flpo
from itertools import combinations
def is_collinear(p1, p2, p3):
(x1, y1), (x2, y2), (x3, y3) = p1, p2, p3
return x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2) == 0
def checkio(points):
distinct_lines = []
segments = (set(ps) for ps in combinations(map(tuple, points), 3) if is_collinear(*ps))
for line in segments:
same_lines = next((l for l in distinct_lines if len(line & l) >= 2), None)
if same_lines:
same_lines |= line
else:
distinct_lines.append(line)
return len(distinct_lines)
Jan. 2, 2018