Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
itertools.combinations solution in Clear category for The Rows of Cakes by David_Jones
from itertools import combinations
def is_collinear(point_1, point_2, point_3):
x1, y1 = point_1
x2, y2 = point_2
x3, y3 = point_3
return (x2 - x1) * (y3 - y1) == (y2 - y1) * (x3 - x1)
def checkio(cakes):
lines = set()
for cake_1, cake_2 in combinations(cakes, 2):
line = frozenset(tuple(cake_3) for cake_3 in cakes
if is_collinear(cake_1, cake_2, cake_3))
if len(line) > 2:
lines.add(line)
return len(lines)
May 17, 2019