Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Using Lightbulb intro solution in Clear category for Lightbulb Start Watching by dig
from datetime import datetime
from typing import List, Optional
def sum_light1(els: List[datetime]) -> int:
total_time=datetime(2010, 1, 1, 1, 1 , 1)-datetime(2010, 1, 1, 1, 1 , 1)#init time in 0 in this format
for i in range (len(els)):
if i%2 == 1:
total_time += els[i]-els[i-1]
return total_time.total_seconds()
def sum_light(els: List[datetime], start_watching: Optional[datetime] = None) -> int:
if not start_watching:
return sum_light1(els)
while els and els[0]<=start_watching:
els.pop(0)
return sum_light1([start_watching]+els)
if __name__ == "__main__":
print("Example:")
print(
sum_light(
[
datetime(2015, 1, 12, 10, 0, 0),
datetime(2015, 1, 12, 10, 0, 10),
],
datetime(2015, 1, 12, 10, 0, 5),
)
)
assert (
sum_light(
els=[
datetime(2015, 1, 12, 10, 0, 0),
datetime(2015, 1, 12, 10, 0, 10),
],
start_watching=datetime(2015, 1, 12, 10, 0, 5),
)
== 5
)
assert (
sum_light(
[
datetime(2015, 1, 12, 10, 0, 0),
datetime(2015, 1, 12, 10, 0, 10),
],
datetime(2015, 1, 12, 10, 0, 0),
)
== 10
)
assert (
sum_light(
[
datetime(2015, 1, 12, 10, 0, 0),
datetime(2015, 1, 12, 10, 10, 10),
datetime(2015, 1, 12, 11, 0, 0),
datetime(2015, 1, 12, 11, 10, 10),
],
datetime(2015, 1, 12, 11, 0, 0),
)
== 610
)
assert (
sum_light(
[
datetime(2015, 1, 12, 10, 0, 0),
datetime(2015, 1, 12, 10, 10, 10),
datetime(2015, 1, 12, 11, 0, 0),
datetime(2015, 1, 12, 11, 10, 10),
],
datetime(2015, 1, 12, 11, 0, 10),
)
== 600
)
assert (
sum_light(
[
datetime(2015, 1, 12, 10, 0, 0),
datetime(2015, 1, 12, 10, 10, 10),
datetime(2015, 1, 12, 11, 0, 0),
datetime(2015, 1, 12, 11, 10, 10),
],
datetime(2015, 1, 12, 10, 10, 0),
)
== 620
)
assert (
sum_light(
[
datetime(2015, 1, 12, 10, 0, 0),
datetime(2015, 1, 12, 10, 10, 10),
datetime(2015, 1, 12, 11, 0, 0),
datetime(2015, 1, 12, 11, 10, 10),
datetime(2015, 1, 12, 11, 10, 11),
datetime(2015, 1, 12, 12, 10, 11),
],
datetime(2015, 1, 12, 12, 10, 11),
)
== 0
)
assert (
sum_light(
[
datetime(2015, 1, 12, 10, 0, 0),
datetime(2015, 1, 12, 10, 10, 10),
datetime(2015, 1, 12, 11, 0, 0),
datetime(2015, 1, 12, 11, 10, 10),
datetime(2015, 1, 12, 11, 10, 11),
datetime(2015, 1, 12, 12, 10, 11),
],
datetime(2015, 1, 12, 12, 9, 11),
)
== 60
)
print("The second mission in series is done? Click 'Check' to earn cool rewards!")
March 22, 2023