Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Simpler O(n^4) solution in Clear category for The Square Chest by DiZ
def checkio(lines_list, g=4):
'''Enumerate all squares in a grid of size 'g'
and count the ones in the list of lines.'''
edges = {tuple(sorted(l)) for l in lines_list}
return sum(all({(e+k , e+k+1), #Top
(e+g*k , e+g*(k+1)), #Left
(e+g*n+k, e+g*n+k+1), #Bottom
(e+n+g*k, e+n+g*(k+1)) #Right
} <= edges for k in range(n))
for n in range(1, g)
for e in range(1, g**2))
Aug. 6, 2014
Comments: