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!
38
Upvotes
View all comments
Show parent comment
2
u/ElecNinja Dec 04 '18
After you've sorted the input, you only need the minutes and the action so just splitting on the ']' character would probably have been enough and just taking some chunks from the strings.
So an input like "[1518-09-17 00:04] Guard #509 begins shift" would be split into "[1518-09-17 00:04]" and " Guard #509 begins shift". And then you can with that to get the minutes and what to do with it.
Though for regex, it was pretty simple with Python; the main thing was escaping the brackets in the regex string. Here's my regex to get the dates, times, and action portions from the input.
groups = re.match(r'\[(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2})\] (.*)', line)