from itertools import permutations
from operator import add
def construct(pieces):
''' returns a list of heights of pieces '''
x = []
x.extend(e for y in pieces[:-1] for e in y[:-1])
return x + pieces[-1]
def broken_window(pieces):
amount = set(range(len(pieces)))
for case in range(1, len(pieces)): # divide a pieces on two parts. In first part will be `case` pieces
for part1 in permutations(amount, case): # Ok. first part is done
first_part = construct([pieces[i] for i in part1]) # Now I build a heights of pieces from first part
for part2 in permutations(amount - set(part1)): # Ok. second part is done
second_part = construct([pieces[j][::-1] for j in part2]) # Now I build a heights of pieces from second part
if len(first_part) != len(second_part): # If lengths not equals, continue
continue
if len(set(map(add, first_part, second_part))) == 1: # If I add i paices and get the same height -> all good -> return two parts
return list(part2), list(part1)