Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First (='ω'=) < simple but laborious solution in Clear category for The Square Chest by Magu
from typing import List
def checkio(lines_list: List[List[int]]) -> int:
laborious = [[(1, 2), (1, 5), (2, 6), (5, 6)], [(2, 3), (2, 6), (3, 7), (6, 7)], \
[(3, 4), (3, 7), (4, 8), (7, 8)], [(5, 6), (5, 9), (6, 10), (9, 10)], [(6, 7), (6, 10), (7, 11), (10, 11)], \
[(7, 8), (7, 11), (8, 12), (11, 12)], [(9, 10), (9, 13), (10, 14), (13, 14)], \
[(10, 11), (10, 14), (11, 15), (14, 15)], [(11, 12), (11, 15), (12, 16), (15, 16)], \
[(1, 2), (2, 3), (1, 5), (3, 7), (5, 9), (7, 11), (9, 10), (10, 11)], \
[(2, 3), (3, 4), (2, 6), (4, 8), (6, 10), (8, 12), (10, 11), (11, 12)], \
[(5, 6), (6, 7), (5, 9), (7, 11), (9, 13), (11, 15), (13, 14), (14, 15)], \
[(6, 7), (7, 8), (6, 10), (8, 12), (10, 14), (12, 16), (14, 15), (15, 16)], \
[(1, 2), (2, 3), (3, 4), (1, 5), (4, 8), (5, 9), (8, 12), (9, 13), (12, 16), (13, 14), (14, 15), (15, 16)]]
cnt = 0
for el in laborious:
if {(l[0], l[1]) if l[0] < l[1] else (l[1], l[0]) for l in lines_list}.issuperset(set(el)): cnt += 1
return cnt
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!")
Nov. 2, 2021
Comments: