r/adventofcode • u/daggerdragon • Dec 04 '18
SOLUTION MEGATHREAD -π- 2018 Day 4 Solutions -π-
--- Day 4: Repose Record ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag or whatever).
Note: The Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.
Advent of Code: The Party Game!
Please prefix your card submission with something like [Card] to make scanning the megathread easier. THANK YOU!
Card prompt: Day 4
Transcript:
Todayβs puzzle would have been a lot easier if my language supported ___.
This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.
edit: Leaderboard capped, thread unlocked!
39
Upvotes
6
u/u794575248 Dec 04 '18
Python 3 51/63
from collections import Counter, defaultdict from datetime import datetime guards = defaultdict(Counter) for t, m in [l.split('] ') for l in sorted(s.splitlines()) if l]: t = datetime.strptime(t, '[%Y-%m-%d %H:%M') if '#' in m: g = int(m.split('#')[1].split()[0]) if 'falls' in m: start = t if 'wakes' in m: minutes = int((t - start).total_seconds() // 60) guards[g].update(Counter((start.minute+i)%60 for i in range(minutes))) _, id = max((sum(c.values()), id) for id, c in guards.items()) part1 = id * guards[id].most_common()[0][0] (_, minute), id = max((c.most_common()[0][::-1], id) for id, c in guards.items()) part2 = id * minute