Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Four winds beneath my wings solution in Clear category for Lightbulb End Watching by veky
import contextlib, statistics, itertools, datetime
def sum_light(els, start_watching=datetime.datetime.min,
end_watching=datetime.datetime.max):
"""How long the light bulb has been turned on."""
result, it = datetime.timedelta(), itertools.chain(els, [end_watching])
with contextlib.suppress(StopIteration):
while ...:
start = statistics.median([start_watching, next(it), end_watching])
end = statistics.median([start_watching, next(it), end_watching])
result += end - start
return result.total_seconds()
Nov. 14, 2020
Comments: