Passed
Push — master ( 118bce...cc2450 )
by Ken M.
01:43
created

lightbulb_intro   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 44
dl 0
loc 58
rs 10
c 0
b 0
f 0
wmc 4

2 Functions

Rating   Name   Duplication   Size   Complexity  
A chunk() 0 2 1
A sum_light() 0 2 3
1
from datetime import datetime
2
from operator import sub
3
from typing import List
4
5
6
def chunk(lst, n):
7
    return zip(*[iter(lst)] * n)
8
9
10
def sum_light(els: List[datetime]) -> int:
11
    return sum(map(lambda x: x.total_seconds(), list(map(lambda x: x[1]-x[0], chunk(els, 2)))))
12
13
14
if __name__ == '__main__':
15
    print("Example:")
16
    print(sum_light([
17
        datetime(2015, 1, 12, 10, 0, 0),
18
        datetime(2015, 1, 12, 10, 10, 10),
19
        datetime(2015, 1, 12, 11, 0, 0),
20
        datetime(2015, 1, 12, 11, 10, 10),
21
    ]))
22
23
    # These "asserts" are used for self-checking and not for an auto-testing
24
    assert sum_light(els=[
25
        datetime(2015, 1, 12, 10, 0, 0),
26
        datetime(2015, 1, 12, 10, 10, 10),
27
    ]) == 610
28
29
    assert sum_light([
30
        datetime(2015, 1, 12, 10, 0, 0),
31
        datetime(2015, 1, 12, 10, 10, 10),
32
        datetime(2015, 1, 12, 11, 0, 0),
33
        datetime(2015, 1, 12, 11, 10, 10),
34
    ]) == 1220
35
36
    assert sum_light([
37
        datetime(2015, 1, 12, 10, 0, 0),
38
        datetime(2015, 1, 12, 10, 10, 10),
39
        datetime(2015, 1, 12, 11, 0, 0),
40
        datetime(2015, 1, 12, 11, 10, 10),
41
        datetime(2015, 1, 12, 11, 10, 10),
42
        datetime(2015, 1, 12, 12, 10, 10),
43
    ]) == 4820
44
45
    assert sum_light([
46
        datetime(2015, 1, 12, 10, 0, 0),
47
        datetime(2015, 1, 12, 10, 0, 1),
48
    ]) == 1
49
50
    assert sum_light([
51
        datetime(2015, 1, 12, 10, 0, 0),
52
        datetime(2015, 1, 12, 10, 0, 10),
53
        datetime(2015, 1, 12, 11, 0, 0),
54
        datetime(2015, 1, 13, 11, 0, 0),
55
    ]) == 86410
56
57
    print("The first mission in series is completed? Click 'Check' to earn cool rewards!")
58