aboutsummaryrefslogtreecommitdiff
path: root/challenge-128/abigail/python/ch-2.py
blob: 85cb8df8e63e6b2a681f42baacfacd747b982c32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/opt/local/bin/python

#
# See ../README.md
#

#
# Run as: python ch-1.py < input-file
#

import re

def get_time (time):
    hours, minutes = map (lambda x: int (x), time . split (":"))
    return (60 * hours + minutes)

def read_times ():
    return (list (map (get_time,
                       re . findall (r'[0-9][0-9]:[0-9][0-9]', input ()))))

arrivals   = read_times ()
departures = read_times ()

trains = [0] * (24 * 60)

for i in range (len (arrivals)):
    arrival   = arrivals [i]
    departure = departures [i]
    for i in range (arrival, departure + 1):
        trains [i] = trains [i] + 1
    if departure < arrival:
        for i in range (0, departure + 1):
            trains [i] = trains [i] + 1
        for i in range (arrival, 24 * 60):
            trains [i] = trains [i] + 1

print (max (trains))