Skip to content

Commit c0d1be5

Browse files
committed
Day 4 - solved part 2 (ugly but works)
1 parent 3b7d054 commit c0d1be5

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

04/solution.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def epoch(x):
88
x = x.split(" ")
99
d = list(map(int,x[0].split("-")))
1010
t = list(map(int,x[1].split(":")))
11-
return datetime.datetime(d[0], d[1], d[2], t[0], t[1])#.timestamp()
11+
return datetime.datetime(d[0], d[1], d[2], t[0], t[1])
1212

1313
data = [{"timestamp": epoch(x[0]), "cmd": x[1]} for x in data]
1414
data = sorted(data, key = lambda k: k["timestamp"])
@@ -39,4 +39,19 @@ def epoch(x):
3939
for x in minutes:
4040
all_minutes += x
4141

42-
print(Counter(all_minutes).most_common(1)[0][0] * sleepyhead)
42+
print("First part: " + str(Counter(all_minutes).most_common(1)[0][0] * sleepyhead))
43+
44+
# Part 2
45+
naps = {}
46+
47+
for g,n in guards.items():
48+
minutes = [[z.minute for z in rrule.rrule(rrule.MINUTELY, dtstart=x[0], until=x[-1])] for x in n]
49+
all_minutes = []
50+
51+
for x in minutes:
52+
all_minutes += x
53+
naps[g] = Counter(all_minutes).most_common(1)[0]
54+
55+
naps = sorted(naps.items(), key = lambda k: k[1][1], reverse=True)
56+
57+
print("Second part: " + str(naps[0][0] * naps[0][1][0]))

0 commit comments

Comments
 (0)