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 Molot
from typing import List
from itertools import chain
def checkio(lines_list: List[List[int]]) -> int:
"""Return the quantity of squares"""
sq1 = [{(i,i+1), (i+1,i+5), (i,i+4), (i+4,i+5)}
for i in [j for j in range(1,12) if j % 4 != 0]]
sq2 = [{(i,i+1), (i+1, i+2), (i+2,i+6), (i+6,i+10), (i+9,i+10), (i+8,i+9),
(i+4,i+8), (i,i+4)} for i in [j for j in [1, 2, 5, 6]]]
sq3 = [{(1,2), (2,3), (3,4), (4,8), (8,12), (12,16), (15,16), (14,15),
(13,14), (9,13), (5,9), (1,5)}]
samples = list(chain(sq1, sq2, sq3))
lines = {tuple(sorted(l)) for l in lines_list}
return sum([sample.issubset(lines) for sample in samples] )
if __name__ == '__main__':
print("Example:")
print(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]]))
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"
print("Coding complete? Click 'Check' to earn cool rewards!")
June 13, 2018
Comments: