January 10, 2025

Solution for Advent of Code 2018 - Day 4: Repose Record

Link to the puzzle text

Part 1

In this puzzle we have log entries for several guards over several days. The guards arrive at their job, fall asleep and wake up at different times. We should analyse the logs and find the guard asleep the most and the minute they most likely sleep.

To start with, the logs are in a random order. They all start with a timestamp, so we sorted them to get a chronological view. We then create an array for every guard and count how often the guard is asleep in this minute. Finally we sum the amount of minutes slept for every guard and find the guard with the highest value.

Part 2

In part 2, we should find the guard who slept in a specific minute the most often.

We can reuse the sleep schedule from part 1, and itstead of summing take the max.

Link to my solutions

No comments:

Post a Comment