Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Lightbulb End Watching solution in Clear category for Lightbulb End Watching by JimmyCarlos
from datetime import datetime
def sum_light(button_presses, start_watching=None, end_watching=None) -> int:
"""Calculate how long the light bulb has been turned on."""
time_on = 0
if end_watching:
button_presses = [x for x in button_presses if x <= end_watching]
if len(button_presses) % 2 == 1: button_presses.append(end_watching)
if start_watching:
button_presses = [x for x in button_presses if x >= start_watching]
if len(button_presses) % 2 == 1: button_presses = [start_watching] + button_presses
for a,b in zip(button_presses[::2],button_presses[1::2]):
time_on += (b-a).total_seconds()
return time_on
Nov. 13, 2020
Comments: