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 Andreas_Strus
def checkio(lines_list):
count = 0
l = lines_list
for x in range(len(lines_list)):
l[x].sort()
for x in range(len(lines_list)):
if l[x][0] + 1 == l[x][1] and [l[x][0], l[x][0] + 4] in l and [l[x][1], l[x][1] + 4] in l and [l[x][0]+4, l[x][1] + 4] in l:
count = count + 1
if l[x][0] + 1 == l[x][1] and[l[x][0], l[x][0] + 4] in l and [l[x][0] +4 , l[x][0] + 8] in l and [l[x][1], l[x][1] + 1] in l and [l[x][1] +1, l[x][1] + 5] in l and [l[x][1] +5, l[x][1] + 9] in l and [l[x][0]+8, l[x][1] + 8] in l and [l[x][0]+9, l[x][1] + 9] in l:
count = count +1
if [1,2] in l and [2,3] in l and [3,4] in l and [1,5] in l and [5,9] in l and [9, 13] in l and [13, 14] in l and [14, 15] in l and [15, 16] in l and [4, 8] in l and [8, 12] in l and [12, 16] in l:
count = count + 1
return count
if __name__ == '__main__':
assert (checkio([[16,15],[16,12],[15,11],[11,12],[11,10],[10,14],[9,10],[14,13],[13,9],[15,14]]) == 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"
Oct. 24, 2016