Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
3 lines proc solution in Creative category for Multiple Lightbulbs by Kosya
from datetime import datetime
def sum_light(els, start_watching=datetime.min, end_watching=datetime.max):
bulbs, els = set(), [i if type(i) == tuple else (i, 0) for i in els]
return sum(max((min(b[0], end_watching) - max(a, start_watching)).total_seconds(), 0) * bool(bulbs := bulbs ^ {num})
for (a, num), b in zip(els, els[1::] + [(end_watching, 0)]))
Dec. 28, 2023