Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
O(n^4) solution in Clear category for The Rows of Cakes by Dima_Shul_chevskij
from itertools import product
def checkio(cakes):
def is_on_line(x, y, z):
return (z[1] - x[1]) * (y[0] - x[0]) == (z[0] - x[0]) * (y[1] - x[1])
def unique_present_line(x, y):
return tuple([tuple(p) for p in cakes if is_on_line(x, y, p)][:2])
return len({unique_present_line(x, y)
for x, y, z in product(cakes, repeat=3)
if x < y < z and is_on_line(x, y, z)})
March 9, 2018
Comments: