Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
y=a*x+b solution in Clear category for The Rows of Cakes by martin_b
from itertools import combinations
def checkio(cakes):
inf = float("inf")
rows = set()
for c in combinations(cakes, 3):
p1, p2, p3 = complex(*c[0]), complex(*c[1]), complex(*c[2])
l = p1 - p2
if l.real != 0:
a = l.imag / l.real
b = p1.imag - p1.real * a
if p3.imag - b == a * p3.real:
rows.add((a, b))
else:
a = inf
b = p1.real
if p3.real == b:
rows.add((a, b))
return len(rows)
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert checkio([[3, 3], [5, 5], [8, 8], [2, 8], [8, 2]]) == 2
assert checkio(
[[2, 2], [2, 5], [2, 8], [5, 2], [7, 2], [8, 2],
[9, 2], [4, 5], [4, 8], [7, 5], [5, 8], [9, 8]]) == 6
Jan. 19, 2016