Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for The Square Chest by PythOff
def checkio(lines_list):
res = 0
small = []
middle = []
large = [[1,2],[1,5],[2,3],[3,4],[4,8],[5,9],[8,12],[9,13],[12,16],[13,14],[14,15],[15,16]]
small.append([[1,2],[1,5],[2,6],[5,6]])
small.append([[2,3],[2,6],[3,7],[6,7]])
small.append([[3,4],[3,7],[4,8],[7,8]])
small.append([[7,8],[7,11],[8,12],[11,12]])
small.append([[6,7],[6,10],[7,11],[10,11]])
small.append([[5,6],[5,9],[6,10],[9,10]])
small.append([[9,10],[9,13],[10,14],[13,14]])
small.append([[10,11],[10,14],[11,15],[14,15]])
small.append([[11,12],[11,15],[12,16],[15,16]])
middle.append([[1,2],[1,5],[2,3],[3,7],[5,9],[7,11],[9,10],[10,11]])
middle.append([[2,3],[2,6],[3,4],[4,8],[6,10],[8,12],[10,11],[11,12]])
middle.append([[6,7],[6,10],[7,8],[8,12],[10,14],[12,16],[14,15],[15,16]])
middle.append([[5,6],[5,9],[6,7],[7,11],[9,13],[11,15],[13,14],[14,15]])
for i in range (len(lines_list)):
lines_list[i] = sorted(lines_list[i])
for i in range (len(small)):
if all(x in lines_list for x in small[i]):
res += 1
for i in range (len(middle)):
if all(x in lines_list for x in middle[i]):
res += 1
if all(x in lines_list for x in large):
res += 1
return res
if __name__ == '__main__':
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"
Nov. 5, 2016