Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
y = ax + b solution in Clear category for The Rows of Cakes by l.szyman10
from itertools import combinations
def in_line(x, y, to_check):
"""" check if point to_check is in line created by points x, y """
try:
a = (y[1]-x[1])/(y[0]-x[0])
b = x[1] - a * x[0]
except ZeroDivisionError:
return to_check[0] == x[0]
return to_check[1] == a * to_check[0] + b
def checkio(cakes):
cakes = {tuple(i) for i in cakes}
comb = combinations(cakes, 2)
lines = []
for pair in comb:
temp = cakes - set(pair)
line = set(pair)
for point in temp:
if in_line(*pair, point): line.add(point)
if len(line) > 2 and line not in lines: lines.append(line)
return len(lines)
Oct. 15, 2020