Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
2 lines proc (one long) solution in Clear category for Lightbulb End Watching by CDG.Axel
from datetime import datetime
from typing import List
def sum_light(els: List[datetime], start_watching = None, end_watching = None) -> int:
"""
how long the light bulb has been turned on
"""
sw, ew = start_watching or els[0], end_watching or els[-1]
return sum((min(ew, max(b, sw)) - min(ew, max(a, sw))).total_seconds()
for a, b in zip(els[::2], els[1::2]+[ew]))
Oct. 31, 2021
Comments: