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 jtarnowska
def checkio(lines_list):
"""Return the quantity of squares"""
lines_list.sort()
sorted_pares = []
for pare in lines_list:
pare.sort()
sorted_pares.append(pare)
#print(sorted_pares)
count = 0
list1 = sorted_pares[:]
print(list1)
#print(list1)
for pare in sorted_pares:
if (pare == [1,2] and [2,6] in list1 and [1,5] in list1 and [5,6] in list1):
count = count + 1
list1.remove(pare)
#print(list1)
#print(count)
list2 = sorted_pares[:]
print(list2)
for pare in sorted_pares:
if (pare == [2,3] and [3,7] in list2 and [2,6] in list2 and [6,7] in list2):
count = count + 1
list2.remove(pare)
# print(list2)
#print(count)
list3 = sorted_pares[:]
print(list3)
for pare in sorted_pares:
if (pare == [3,4] and [4,8] in list3 and [3,7] in list3 and [7,8] in list3):
count = count + 1
list3.remove(pare)
# print(list3)
#print(count)
list4 = sorted_pares[:]
print(list4)
for pare in sorted_pares:
if (pare == [5,6] and [6,10] in list4 and [5,9] in list4 and [9,10] in list4):
count = count + 1
list4.remove(pare)
# print(list4)
#print(count)
list5 = sorted_pares[:]
print(list5)
for pare in sorted_pares:
if (pare == [6,7] and [7,11] in list5 and [6,10] in list5 and [10,11] in list5):
count = count + 1
list5.remove(pare)
# print(list5)
#print(count)
list6 = sorted_pares[:]
print(list6)
for pare in sorted_pares:
if (pare == [7,8] and [8,12] in list6 and [7,11] in list6 and [11,12] in list6):
count = count + 1
list6.remove(pare)
# print(list6)
#print(count)
list7 = sorted_pares[:]
print(list7)
for pare in sorted_pares:
if (pare == [9,10] and [10,14] in list7 and [9,13] in list7 and [13,14] in list7):
count = count + 1
list7.remove(pare)
# print(list7)
#print(count)
list8 = sorted_pares[:]
print(list8)
for pare in sorted_pares:
if (pare == [10,11] and [11,15] in list8 and [10,14] in list8 and [14,15] in list8):
count = count + 1
list8.remove(pare)
# print(list8)
#print(count)
list9 = sorted_pares[:]
print(list9)
for pare in sorted_pares:
if (pare == [11,12] and [12,16] in list9 and [11,15] in list9 and [15,16] in list9):
count = count + 1
list9.remove(pare)
# print(list9)
list10 = sorted_pares[:]
for pare in sorted_pares:
if (pare == [1,2] and [2,3] in list10 and [3,7] in list10 and [7,11] in list10 and [1,5] in list10 and [5,9] in list10 and [9,10] in list10 and [10,11] in list10):
count = count + 1
list10.remove(pare)
# print(list10)
#print(count)
list11 = sorted_pares[:]
for pare in sorted_pares:
if (pare == [2,3] and [3,4] in list11 and [4,8] in list11 and [8,12] in list11 and [2,6] in list11 and [6,10] in list11 and [10,11] in list11 and [11,12] in list11):
count = count + 1
list11.remove(pare)
# print(list11)
#print(count)
list12 = sorted_pares[:]
for pare in sorted_pares:
if (pare == [5,6] and [6,7] in list12 and [7,11] in list12 and [11,15] in list12 and [5,9] in list12 and [9,13] in list12 and [13,14] in list12 and [14,15] in list12):
count = count + 1
list12.remove(pare)
# print(list12)
#print(count)
list13 = sorted_pares[:]
print(list13)
for pare in sorted_pares:
if (pare == [6,7] and [7,8] in list13 and [8,12] in list13 and [12,16] in list13 and [6,10] in list13 and [10,14] in list13 and [14,15] in list13 and [15,16] in list13):
count = count + 1
list13.remove(pare)
# print(list13)
#print(count)
list14 = sorted_pares[:]
for pare in sorted_pares:
if (pare == [1,2] and [2,3] in list14 and [3,4] in list14 and [4,8] in list14 and [8,12] in list14 and [12,16] in list14 and [1,5] in list14 and [5,9] in list14 and [9,13] in list14 and [13,14] in list14 and [14,15] in list14 and [15,16] in list14):
count = count + 1
list14.remove(pare)
print(count)
return(count)
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. 14, 2017