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 nubatamax
l1 = [(n, n + 4, n + 5, n + 1)
for n in (1, 2, 3, 5, 6, 7, 9, 10, 11, 13, 14, 15)]
l2 = [(n, n + 4, n + 8, n + 9, n + 10, n + 6, n + 2, n + 1)
for n in (1, 2, 5, 6)]
l3 = [(1, 5, 9, 13, 14, 15, 16, 12, 8, 4, 3, 2)]
def seg_gen(path):
l = len(path)
for i in range(l):
yield sorted((path[i], path[(i + 1) % l]))
def checkio(lines_list):
# sort given segments in the list, just in case
segments = [sorted(segment) for segment in lines_list]
count = 0
for square_list in (l1, l2, l3):
for square in square_list:
if all([seg in segments for seg in seg_gen(square)]):
count += 1
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
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
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"
Feb. 26, 2014
Comments: