Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
all lines found twice solution in Clear category for The Rows of Cakes by juestr
from fractions import Fraction
from itertools import combinations
def checkio(cakes):
def create_line(a, b):
ax, ay = a
bx, by = b
return ax if ax == bx else ((k:=Fraction(by - ay, bx - ax)), ay - k * ax)
lines2p, lines3p = set(), set()
for a, b in combinations(cakes, 2):
line = create_line(a, b)
if line not in lines3p:
(lines3p if line in lines2p else lines2p).add(line)
return len(lines3p)
Oct. 19, 2021
Comments: