Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
22-liner: picasso solution in Clear category for Painting Wall by przemyslaw.daniel
from itertools import combinations
def calc_sum(operations):
while True:
operations = sorted(operations)
overlapping = [(i, j) for i, j in
combinations(operations, 2) if i[1] >= j[0]]
if not overlapping:
break
f = overlapping[0] # first overlapping
operations = [x for x in operations if x not in f]
merged_elem = sorted(f[0] + f[1])
operations += [[merged_elem[0], merged_elem[-1]]]
return sum([x[1]-x[0]+1 for x in operations])
def checkio(required, operations):
for i in range(len(operations)):
if calc_sum(operations[:i+1]) >= required:
return i+1
return -1
Oct. 24, 2016