See Neil Gall's wonderful post for a more functional-paradigm approach. Kotlin not being pure-functional makes me lean into the procedural style more often than I'd like.
Anyway...
Part 1
I didn't read the problem properly. Some key things I missed:
The input data is random.
We only care about minutes.
There's only ever one guard on duty (not a stack of sleeping and awake guards).
Fortunately, once I knew what I was supposed to be recording, it was just a simple matter of adding sleeping events to guards.
So, the thing that threw me here is that some guards don't fall asleep, leading .maxBy to return null. Otherwise, this was a fairly simple modification of the first part, just aggregating at different points. At this point, I'm wondering if Eric Wastl is experimenting with reversing the difficulties this year. This is two in a row where the heavy lifting gets done in part 1. We'll see when tomorrow's drops!
Non-functional-paradigm kotlin solution
See Neil Gall's wonderful post for a more functional-paradigm approach. Kotlin not being pure-functional makes me lean into the procedural style more often than I'd like.
Anyway...
Part 1
I didn't read the problem properly. Some key things I missed:
Fortunately, once I knew what I was supposed to be recording, it was just a simple matter of adding sleeping events to guards.
Part 2
So, the thing that threw me here is that some guards don't fall asleep, leading
.maxBy
to returnnull
. Otherwise, this was a fairly simple modification of the first part, just aggregating at different points. At this point, I'm wondering if Eric Wastl is experimenting with reversing the difficulties this year. This is two in a row where the heavy lifting gets done in part 1. We'll see when tomorrow's drops!and since I got bored waiting for some scans to complete, here's what my schedule looks like!
I should probably just pick the days that don't have guards!
I like your use of
-en
suffixes to denote verbs. Makes a lot of sense, actually, easy to glean intent.Haha, I was tired and started with
awaken
and I thoughtasleepen
was really hilarious.Of course once I realized that there was a distinction between going on duty and waking up from a sleep, I was honor-bound to add
ondutyen