Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for The Square Chest by Nuszwkartlo
def checkio(lines_list):
squares = 0
for item in range (0, len(lines_list)):
lines_list[item] = sorted(lines_list[item])
for x in range (0,12):
if ([x,x+1] in lines_list and [x,x+4] in lines_list and [x+1,x+5] in lines_list and [x+4,x+5] in lines_list):
squares += 1
for x in range (0,7):
if ([x,x+1] in lines_list and [x+1,x+2] in lines_list and [x,x+4] in lines_list and [x+4,x+8] in lines_list
and [x+2,x+6] in lines_list and [x+6,x+10] in lines_list and [x+8,x+9] in lines_list and [x+9,x+10] in lines_list):
squares += 1
if ([1,2] in lines_list and [2,3] in lines_list and [3,4] in lines_list
and [4,8] in lines_list and [8,12] in lines_list and [12,16] in lines_list and [15,16] in lines_list
and [14,15] in lines_list and [13,14] in lines_list and [9,13] in lines_list and [5,9] in lines_list and [1,5] in lines_list):
squares += 1
return squares
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"
Jan. 23, 2016