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 jantechner
def is_square(w, n, list):
if n == 1:
if [w,w+n] in list and [w+4, w+4+n] in list and [w, w+4] in list and [w+n, w+n+4] in list:
return 1
else:
return 0
if n==2:
if [w,w+1] in list and [w+1, w+2] in list and [w+8, w+9] in list and [w+9, w+10] in list and [w,w+4] in list and [w+4, w+8] in list and [w+2, w+6] in list and [w+6, w+10] in list:
return 1
else:
return 0
if n==3:
if [1,2] in list and [2,3] in list and [3,4] in list and [4,8] in list and [8,12] in list and [12,16] in list and [1,5] in list and [5,9] in list and [9,13] in list and [13, 14] in list and [14, 15] in list and [15,16] in list:
return 1
else:
return 0
def checkio(lines_list):
res = 0
tmp = lines_list
lines_list = []
for el in tmp:
lines_list.append(sorted(el))
for i in range(1,4):
if is_square(i, 1, lines_list):
res +=1
if is_square(i+4, 1, lines_list):
res +=1
if is_square(i+8, 1, lines_list):
res +=1
for i in range(1,3):
if is_square(i, 2, lines_list):
res +=1
if is_square(i+4, 2, lines_list):
res +=1
if is_square(i, 3, lines_list):
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"
Dec. 7, 2016