Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
On the square solution in Clear category for The Square Chest by evrur97
from typing import List
# Define maps for every type of square
SMALL_SQUARE = [[0,1],[1,5],[4,5],[0,4]]
MEDIUM_SQUARE = [[0,1], [1,2], [2,6], [6,10], [9,10], [8,9], [4,8], [0,4]]
LARGE_SQUARE = [[0,1], [1,2], [2,3], [3,7], [7,11], [11,15], [14,15], [13,14], [12,13], [8,12], [4,8], [0,4]]
# Identify where each type of square can originate
A = [1]
B = [1, 2, 5, 6]
C = [1, 2, 3, 5, 6, 7, 9, 10, 11]
def make_squares(origins, shape):
"""
Given an origin and a map, create the set of lines
that represent the given shape
"""
test_square_collection = []
for x in origins:
test_square = []
for s in shape:
test_square.append([x + s[0], x + s[1]])
test_square_collection.append(test_square)
return test_square_collection
def checkio(lines_list: List[List[int]]) -> int:
# Clean up any lines that are not specified as
# low number, high number
sorted_lines_list = []
for line in lines_list:
sorted_lines_list.append(sorted(line))
count = 0
# Build a collection of all possible squares
test_square_collection = make_squares(A,LARGE_SQUARE)
test_square_collection += make_squares(B,MEDIUM_SQUARE)
test_square_collection += make_squares(C,SMALL_SQUARE)
for test_square in test_square_collection:
found = True
for edge in test_square:
if edge not in sorted_lines_list:
found = False
break
if found:
count += 1
return count
Aug. 2, 2019