Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
a simple idea solution in Clear category for Count Squares by rybld2
from itertools import combinations, product
def distance(u, v):
return (u[0] - v[0]) ** 2 + (u[1] - v[1]) ** 2
def is_square(u, v, w, x):
l = u, v, w, x
dist = {distance(p, q) for p, q in product(l, l) if distance(p, q)}
return len(dist) == 2
def count_squares(points: list[list[int]]) -> int:
compt = 0
for c in combinations(points, 4):
if is_square(c[0], c[1], c[2], c[3]): compt += 1
return compt
July 4, 2023