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 zleepy
def getsquare(pos, size):
for i in range(size):
yield (pos + i, pos + i + 1) # top
yield (pos + (i * 4), pos + ((i + 1) * 4)) # left
yield ((pos + size * 4) + i, (pos + size * 4) + i + 1) # bottom
yield ((pos + size) + i * 4, (pos + size) + (i + 1) * 4) # right
def checkio(lines_list):
"""Return the qantity of squares"""
sourceset = set([(min(i[0],i[1]), max(i[0],i[1])) for i in lines_list])
return sum([set(getsquare(j + i * 4, size)) <= sourceset for i in range(0, 3) \
for j in range(1, 4) for size in range(1, min(4 - i, 5 - j))])
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],[10,11],
[9,13],[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"
Nov. 11, 2012
Comments: