Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for The Rows of Cakes by rodka81
from sympy.geometry import Point, Line
from itertools import combinations
from math import gcd
from functools import reduce
def normalize(args):
mcd = reduce(gcd, list(args))
return tuple(a / mcd for a in args)
def checkio(cakes):
lines = set()
for p in combinations(cakes, 3):
points = [Point(x) for x in p]
if Point.is_collinear(*points):
p1, p2, p3 = points
l = Line(p1, p2)
lines.add(normalize(l.coefficients))
return len(lines)
Jan. 4, 2017