Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Painting Wall by Moff
from collections import namedtuple
class Part(namedtuple('Part', 'start stop')):
def union(self, other):
if other.start > self.stop or self.start > other.stop:
return None
return Part(min(self.start, other.start), max(self.stop, other.stop))
@property
def size(self):
return self.stop - self.start + 1
def checkio(size, parts):
current = []
for i, part in enumerate((Part(*p) for p in parts), 1):
for other in current[:]:
union = part.union(other)
if union is not None:
current.remove(other)
part = union
current.append(part)
if sum(p.size for p in current) >= size:
return i
return -1
Aug. 28, 2015