Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
One liner solution in Creative category for Lightbulb Start Watching by CDG.Axel
from datetime import datetime
from typing import List, Optional
def sum_light(els: List[datetime], start_watching = datetime(1, 1, 1)) -> int:
"""
how long the light bulb has been turned on
max(a, start_watching) is equal to if a < start_watching: a = start_watching
max(0, ...) is for cases when start_watching > b
"""
return sum(max(0, (b - max(a, start_watching)).total_seconds()) for a, b in zip(els[::2], els[1::2]))
Nov. 27, 2021
Comments: