Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for The Rows of Cakes by natsuki
import itertools
def on_same_line(p1, p2, p3):
(x1, y1), (x2, y2), (x3, y3) = p1, p2, p3
return y1 * (x2 - x3) + y2 * (x3 - x1) + y3 * (x1 - x2) == 0
def checkio(cakes):
cakes = {(x, y) for x, y in cakes}
lines = set()
for a, b, c in itertools.combinations(cakes, 3):
if on_same_line(a, b, c):
line = {a, b, c} | {p for p in cakes - {a, b, c} if on_same_line(a, b, p)}
lines.add(frozenset(line))
return len(lines)
April 1, 2014
Comments: