Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Speedy category for The Square Chest by yanming1560
def checkio(l):
for i in l:
i.sort()
number=0
for i in range(1,17):
ro=1+(i-0.1)//4
if (i%4==0):
cl=4
else:
cl=i%4
m=int(min(4-ro,4-cl))
for k in range(m):
s=k+1
r=True
for j in range(s):
if ([i+j,i+j+1] in l) and ([i+j*4,i+(j+1)*4] in l)and([i+4*s+j,i+4*s+j+1] in l)and([i+s+j*4,i+s+(j+1)*4] in l):
r=r*True
else:
r=r*False
if (r==True):
number=number+1
return number
if __name__ == '__main__':
checkio([[16,15],[16,12],[15,11],[11,12],[11,10],[10,14],[9,10],[14,13],[13,9],[15,14]])
assert (checkio([[1, 2], [3, 4], [1, 5], [2, 6], [4, 8], [5, 6], [6, 7],
[7, 8], [6, 10], [7, 11], [8, 12], [10, 11],
[10, 14], [12, 16], [14, 15], [15, 16]]) == 3), "First, from description"
assert (checkio([[1, 2], [2, 3], [3, 4], [1, 5], [4, 8],
[6, 7], [5, 9], [6, 10], [7, 11], [8, 12],
[9, 13], [10, 11], [12, 16], [13, 14], [14, 15], [15, 16]]) == 2), "Second, from description"
assert (checkio([[1, 2], [1, 5], [2, 6], [5, 6]]) == 1), "Third, one small square"
assert (checkio([[1, 2], [1, 5], [2, 6], [5, 9], [6, 10], [9, 10]]) == 0), "Fourth, it's not square"
assert (checkio([[16, 15], [16, 12], [15, 11], [11, 10],
[10, 14], [14, 13], [13, 9]]) == 0), "Fifth, snake"
Feb. 13, 2018