This repository was archived by the owner on Oct 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday04.py
More file actions
executable file
·56 lines (42 loc) · 1.35 KB
/
Copy pathday04.py
File metadata and controls
executable file
·56 lines (42 loc) · 1.35 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from collections import defaultdict
from time import strptime
import re
def both():
d = defaultdict(lambda: [0]*60)
with open('input') as f:
curr_time = None
curr_gid = None
result_1 = 0
result_2 = 0
data = f.read().splitlines()
data.sort(key=lambda x: strptime(x.strip().split(']')[0], r'[%Y-%m-%d %H:%M'))
mx = 0
for line in data:
t, event = line.strip().split(']')
t = strptime(t, r'[%Y-%m-%d %H:%M')
if 'begins' in event:
gid = int(re.search(r'#(\d+)', event).group()[1:])
curr_gid = gid
else:
gid = curr_gid
if 'falls' in event:
curr_time = t
elif 'wakes' in event:
if curr_time.tm_yday != t.tm_yday:
curr_time = t.replace(tm_min=0)
for i in range(curr_time.tm_min, t.tm_min):
d[gid][i] += 1
if d[gid][i] > mx:
mx = d[gid][i]
result_2 = i * gid
mx = 0
for k, v in d.items():
s = sum(v)
if s > mx:
mx = s
result_1 = k * v.index(max(v))
return result_1, result_2
def main():
print('Both:', *both())
if __name__ == '__main__':
main()