Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
set <= set solution in Clear category for The Square Chest by Olpag
from typing import List
def checkio(lines_list: List[List[int]]) -> int:
lines_list = {tuple(sorted(i)) for i in lines_list}
count = 0
# get set like this {(1, 2), (1, 5), (2, 6), (5, 6)} from tuple like this (1, 2, 6, 5)
get_square_lines = lambda points, amount: {tuple(sorted((points[i], points[(i+1)%amount]))) for i in range(amount)}
# list of tuples of points for each square [(1, 2, 6, 5), (2, 3, 7, 6), etc...]
# squares_points_list = [(i, i + 1, i + 5, i + 4) for i in range(1, 12) if i%4 != 0]
squares_points_list = [(i, i+1, i+5, i+4) for i in (1, 2, 3, 5, 6, 7, 9, 10, 11)] # squares with side = 1 line
squares_points_list += [(i, i+1, i+2, i+6, i+10, i+9, i+8, i+4) for i in (1, 2, 5, 6)] # + squares with side = 2 lines
squares_points_list += [(i, i+1, i+2, i+3, i+7, i+11, i+15, i+14, i+13, i+12, i+8, i+4) for i in (1,)] # + squares with side = 3 lines
squares_lines_list = [get_square_lines(points, len(points)) for points in squares_points_list]
for i in squares_lines_list:
if i <= lines_list:
count += 1
return(count)
Feb. 25, 2019