Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
using bisect solution in Clear category for Lightbulb Start Watching by ainem
from datetime import datetime
from typing import List, Optional
from bisect import bisect
def sum_light(els: List[datetime], start_watching: Optional[datetime] = None) -> int:
if start_watching:
ind = bisect(els, start_watching)
if ind%2:
# start watching during light is on
els = [start_watching] + els[ind:]
else:
els = els[ind:]
return sum((d2-d1).days * 86400 + (d2-d1).seconds for d1, d2 in zip(els[::2], els[1::2]))
May 20, 2022
Comments: