From b81981da235d8d23698766c0716fa23c43f896e3 Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Wed, 5 Dec 2018 10:44:38 +0000 Subject: [PATCH] Day 4 at last --- advent-of-code.cabal | 12 +- data/advent04.txt | 1003 ++++++++++++++++++++++++++++++++++++++ problems/day04.html | 161 ++++++ src/advent04/advent04.hs | 161 ++++++ 4 files changed, 1336 insertions(+), 1 deletion(-) create mode 100644 data/advent04.txt create mode 100644 problems/day04.html create mode 100644 src/advent04/advent04.hs diff --git a/advent-of-code.cabal b/advent-of-code.cabal index df61f3e..0461b7d 100644 --- a/advent-of-code.cabal +++ b/advent-of-code.cabal @@ -41,4 +41,14 @@ executable advent03 build-depends: base >= 4.7 && < 5 , text , megaparsec - , containers \ No newline at end of file + , containers + +executable advent04 + hs-source-dirs: src/advent04 + main-is: advent04.hs + default-language: Haskell2010 + build-depends: base >= 4.7 && < 5 + , text + , megaparsec + , time + , containers \ No newline at end of file diff --git a/data/advent04.txt b/data/advent04.txt new file mode 100644 index 0000000..694a5fa --- /dev/null +++ b/data/advent04.txt @@ -0,0 +1,1003 @@ +[1518-05-29 00:00] Guard #1151 begins shift +[1518-05-12 00:02] Guard #439 begins shift +[1518-04-11 00:33] falls asleep +[1518-06-23 00:52] wakes up +[1518-10-25 00:48] falls asleep +[1518-09-09 00:55] falls asleep +[1518-10-29 00:18] falls asleep +[1518-10-24 00:43] wakes up +[1518-11-03 00:57] wakes up +[1518-04-10 00:03] falls asleep +[1518-07-17 00:46] wakes up +[1518-10-02 00:47] wakes up +[1518-04-02 00:48] wakes up +[1518-04-27 00:57] wakes up +[1518-07-19 00:46] wakes up +[1518-09-28 00:44] wakes up +[1518-11-05 00:45] wakes up +[1518-11-17 00:50] wakes up +[1518-08-03 00:15] falls asleep +[1518-09-21 00:26] falls asleep +[1518-04-13 00:00] Guard #947 begins shift +[1518-08-03 00:39] falls asleep +[1518-11-23 00:23] wakes up +[1518-08-02 00:27] wakes up +[1518-10-08 00:04] Guard #499 begins shift +[1518-07-12 23:58] Guard #3449 begins shift +[1518-09-07 00:38] wakes up +[1518-11-16 00:43] wakes up +[1518-04-29 00:23] falls asleep +[1518-10-31 00:53] wakes up +[1518-06-25 00:15] wakes up +[1518-10-20 23:50] Guard #947 begins shift +[1518-08-24 00:23] wakes up +[1518-11-11 00:57] wakes up +[1518-06-03 00:01] Guard #947 begins shift +[1518-09-29 00:43] wakes up +[1518-08-24 00:43] wakes up +[1518-07-16 00:10] falls asleep +[1518-06-08 00:21] wakes up +[1518-08-17 00:49] falls asleep +[1518-08-02 00:25] falls asleep +[1518-09-28 00:53] wakes up +[1518-10-19 00:03] Guard #337 begins shift +[1518-04-15 00:53] falls asleep +[1518-09-25 00:52] falls asleep +[1518-07-17 00:39] falls asleep +[1518-11-17 00:04] Guard #2341 begins shift +[1518-06-06 00:08] falls asleep +[1518-08-05 00:09] falls asleep +[1518-04-30 23:56] Guard #809 begins shift +[1518-08-19 00:53] wakes up +[1518-06-07 00:00] Guard #2341 begins shift +[1518-04-15 23:50] Guard #3019 begins shift +[1518-09-02 00:55] wakes up +[1518-11-19 00:59] wakes up +[1518-05-03 00:29] falls asleep +[1518-11-17 23:49] Guard #337 begins shift +[1518-07-02 00:39] wakes up +[1518-05-26 00:53] falls asleep +[1518-06-03 00:20] falls asleep +[1518-07-14 00:08] falls asleep +[1518-05-25 00:03] Guard #1481 begins shift +[1518-03-19 00:24] falls asleep +[1518-06-13 00:41] falls asleep +[1518-07-16 00:49] wakes up +[1518-06-01 00:40] wakes up +[1518-06-24 00:34] wakes up +[1518-04-15 00:00] Guard #499 begins shift +[1518-08-24 23:56] Guard #3019 begins shift +[1518-04-04 00:03] falls asleep +[1518-11-05 00:00] Guard #3119 begins shift +[1518-05-23 00:54] wakes up +[1518-09-19 00:57] wakes up +[1518-09-10 00:56] wakes up +[1518-05-27 00:04] Guard #3067 begins shift +[1518-07-18 00:00] falls asleep +[1518-08-16 00:36] wakes up +[1518-11-12 23:57] Guard #1481 begins shift +[1518-07-02 23:46] Guard #499 begins shift +[1518-08-17 00:14] falls asleep +[1518-07-09 23:57] Guard #2791 begins shift +[1518-04-11 23:59] Guard #3067 begins shift +[1518-09-08 00:20] falls asleep +[1518-11-10 00:41] falls asleep +[1518-06-10 00:29] wakes up +[1518-04-28 00:55] wakes up +[1518-05-22 23:58] Guard #3019 begins shift +[1518-07-06 23:57] Guard #1973 begins shift +[1518-09-25 00:00] Guard #1481 begins shift +[1518-10-22 23:47] Guard #1973 begins shift +[1518-10-12 00:42] wakes up +[1518-06-18 00:41] falls asleep +[1518-10-03 00:22] wakes up +[1518-10-22 00:50] falls asleep +[1518-09-24 00:00] Guard #337 begins shift +[1518-06-30 23:58] Guard #2243 begins shift +[1518-07-01 23:57] Guard #1951 begins shift +[1518-06-27 00:57] wakes up +[1518-06-24 00:56] wakes up +[1518-09-21 00:56] wakes up +[1518-10-06 00:36] wakes up +[1518-04-28 00:16] wakes up +[1518-07-19 23:57] Guard #3067 begins shift +[1518-08-27 00:14] falls asleep +[1518-08-27 00:15] wakes up +[1518-04-10 23:57] Guard #809 begins shift +[1518-10-02 00:04] Guard #2243 begins shift +[1518-09-15 00:47] falls asleep +[1518-04-29 00:01] Guard #439 begins shift +[1518-04-17 00:16] falls asleep +[1518-11-23 00:16] falls asleep +[1518-09-29 00:03] Guard #3449 begins shift +[1518-10-09 00:03] falls asleep +[1518-09-18 00:00] Guard #1951 begins shift +[1518-05-31 00:54] wakes up +[1518-11-07 00:31] wakes up +[1518-09-02 00:44] falls asleep +[1518-07-03 00:55] wakes up +[1518-09-11 00:35] wakes up +[1518-08-05 00:53] wakes up +[1518-06-13 00:55] wakes up +[1518-11-02 00:02] Guard #3119 begins shift +[1518-06-17 00:50] falls asleep +[1518-08-03 00:36] wakes up +[1518-05-02 00:53] falls asleep +[1518-06-25 00:48] wakes up +[1518-11-10 23:58] Guard #3019 begins shift +[1518-08-23 00:36] wakes up +[1518-10-26 00:53] wakes up +[1518-05-02 00:46] wakes up +[1518-07-29 00:45] wakes up +[1518-03-19 00:02] Guard #787 begins shift +[1518-07-16 00:03] Guard #947 begins shift +[1518-10-28 00:02] Guard #1951 begins shift +[1518-10-30 00:04] Guard #947 begins shift +[1518-08-06 00:56] wakes up +[1518-08-05 00:03] Guard #2791 begins shift +[1518-04-04 00:42] falls asleep +[1518-07-06 00:12] wakes up +[1518-06-24 00:46] falls asleep +[1518-05-03 00:59] wakes up +[1518-11-07 00:18] falls asleep +[1518-08-14 00:56] falls asleep +[1518-03-28 00:02] Guard #499 begins shift +[1518-08-07 00:57] wakes up +[1518-07-05 00:53] wakes up +[1518-05-31 00:38] falls asleep +[1518-07-04 00:17] falls asleep +[1518-10-12 00:58] wakes up +[1518-10-08 00:44] falls asleep +[1518-05-22 00:55] wakes up +[1518-07-10 23:57] Guard #947 begins shift +[1518-04-08 00:33] wakes up +[1518-08-08 00:44] falls asleep +[1518-05-19 00:57] wakes up +[1518-04-05 00:01] Guard #499 begins shift +[1518-07-04 00:59] wakes up +[1518-09-27 00:34] falls asleep +[1518-11-01 00:21] wakes up +[1518-11-23 00:32] falls asleep +[1518-10-31 00:36] wakes up +[1518-04-29 00:57] wakes up +[1518-07-10 00:55] wakes up +[1518-10-11 00:09] falls asleep +[1518-10-26 00:28] falls asleep +[1518-10-27 00:36] falls asleep +[1518-10-13 00:36] falls asleep +[1518-05-21 00:35] falls asleep +[1518-07-24 00:07] falls asleep +[1518-03-20 00:00] Guard #499 begins shift +[1518-04-01 00:08] falls asleep +[1518-05-13 00:48] wakes up +[1518-08-18 00:16] falls asleep +[1518-04-08 00:19] falls asleep +[1518-11-11 00:48] wakes up +[1518-09-22 00:16] falls asleep +[1518-04-28 00:27] falls asleep +[1518-07-24 00:36] wakes up +[1518-07-31 00:23] falls asleep +[1518-03-27 00:48] falls asleep +[1518-06-26 00:43] wakes up +[1518-07-13 00:18] falls asleep +[1518-11-11 23:58] Guard #2243 begins shift +[1518-09-15 00:25] falls asleep +[1518-10-09 00:20] falls asleep +[1518-09-30 00:00] Guard #2341 begins shift +[1518-10-29 00:59] wakes up +[1518-08-08 00:14] falls asleep +[1518-05-04 23:56] Guard #1151 begins shift +[1518-05-16 00:19] falls asleep +[1518-09-14 00:59] wakes up +[1518-11-21 00:53] wakes up +[1518-09-19 00:40] wakes up +[1518-08-22 00:30] falls asleep +[1518-10-18 00:29] wakes up +[1518-11-14 00:25] falls asleep +[1518-06-02 00:36] falls asleep +[1518-11-04 00:03] Guard #3449 begins shift +[1518-08-21 00:00] Guard #2089 begins shift +[1518-04-19 00:17] wakes up +[1518-07-28 00:30] falls asleep +[1518-06-09 00:30] falls asleep +[1518-10-09 23:59] Guard #1367 begins shift +[1518-06-21 23:59] Guard #631 begins shift +[1518-10-31 00:51] falls asleep +[1518-10-29 00:04] Guard #89 begins shift +[1518-09-08 00:58] wakes up +[1518-03-31 00:01] Guard #3449 begins shift +[1518-11-20 23:49] Guard #947 begins shift +[1518-09-15 00:50] wakes up +[1518-09-01 00:48] wakes up +[1518-11-14 23:56] Guard #3119 begins shift +[1518-04-17 00:45] wakes up +[1518-08-26 00:02] falls asleep +[1518-03-25 00:00] Guard #2791 begins shift +[1518-06-21 00:00] Guard #3019 begins shift +[1518-08-07 00:10] falls asleep +[1518-09-26 00:24] falls asleep +[1518-10-08 00:24] wakes up +[1518-08-15 23:59] Guard #947 begins shift +[1518-07-31 00:01] Guard #89 begins shift +[1518-04-22 00:26] wakes up +[1518-08-17 00:03] Guard #337 begins shift +[1518-06-04 00:31] falls asleep +[1518-10-08 00:27] falls asleep +[1518-06-02 00:19] falls asleep +[1518-08-01 00:47] wakes up +[1518-05-04 00:00] Guard #1973 begins shift +[1518-10-12 00:53] falls asleep +[1518-09-14 00:22] wakes up +[1518-06-02 00:56] wakes up +[1518-07-25 00:54] falls asleep +[1518-07-03 23:50] Guard #2617 begins shift +[1518-05-13 00:00] Guard #1951 begins shift +[1518-11-01 00:05] falls asleep +[1518-05-03 00:49] falls asleep +[1518-09-18 00:48] falls asleep +[1518-07-25 00:59] wakes up +[1518-11-19 00:28] falls asleep +[1518-04-25 00:21] wakes up +[1518-08-24 00:41] falls asleep +[1518-08-20 00:54] wakes up +[1518-11-15 23:57] Guard #3019 begins shift +[1518-05-15 00:00] falls asleep +[1518-04-09 00:56] wakes up +[1518-10-25 00:58] wakes up +[1518-03-18 00:01] Guard #89 begins shift +[1518-08-05 00:10] wakes up +[1518-09-02 00:40] wakes up +[1518-07-05 00:35] falls asleep +[1518-08-06 00:25] falls asleep +[1518-11-07 23:50] Guard #499 begins shift +[1518-04-24 00:10] falls asleep +[1518-10-30 00:57] falls asleep +[1518-07-09 00:23] falls asleep +[1518-06-26 00:05] falls asleep +[1518-08-04 00:57] wakes up +[1518-05-06 00:01] falls asleep +[1518-10-12 00:00] Guard #3449 begins shift +[1518-06-06 00:47] wakes up +[1518-09-15 00:42] wakes up +[1518-06-14 00:11] wakes up +[1518-05-20 00:33] wakes up +[1518-07-29 00:03] falls asleep +[1518-07-22 00:04] Guard #3449 begins shift +[1518-08-31 00:37] wakes up +[1518-04-06 00:06] falls asleep +[1518-09-27 00:56] wakes up +[1518-07-09 00:11] wakes up +[1518-07-09 00:06] falls asleep +[1518-03-22 00:26] wakes up +[1518-10-16 00:24] falls asleep +[1518-04-13 00:57] wakes up +[1518-03-31 00:42] wakes up +[1518-04-02 00:52] falls asleep +[1518-07-19 00:17] falls asleep +[1518-09-03 00:33] falls asleep +[1518-09-12 00:35] falls asleep +[1518-06-18 00:55] wakes up +[1518-05-15 00:54] wakes up +[1518-05-01 00:33] wakes up +[1518-06-22 00:42] falls asleep +[1518-09-01 00:55] wakes up +[1518-10-17 23:58] Guard #439 begins shift +[1518-04-11 00:46] wakes up +[1518-03-20 00:08] falls asleep +[1518-09-04 00:34] falls asleep +[1518-04-11 00:20] wakes up +[1518-04-18 00:41] wakes up +[1518-09-19 00:49] falls asleep +[1518-06-15 00:39] falls asleep +[1518-06-22 00:48] wakes up +[1518-03-26 23:59] Guard #2617 begins shift +[1518-08-29 00:44] wakes up +[1518-06-01 00:04] Guard #3449 begins shift +[1518-06-17 00:03] Guard #89 begins shift +[1518-07-07 00:35] wakes up +[1518-07-06 00:05] falls asleep +[1518-03-26 00:47] wakes up +[1518-09-20 00:09] falls asleep +[1518-08-29 00:39] falls asleep +[1518-09-27 00:52] falls asleep +[1518-04-09 00:15] falls asleep +[1518-11-08 00:27] wakes up +[1518-09-15 00:18] wakes up +[1518-06-04 00:25] wakes up +[1518-11-22 00:07] falls asleep +[1518-11-11 00:38] falls asleep +[1518-04-15 00:36] falls asleep +[1518-04-03 23:50] Guard #809 begins shift +[1518-07-18 00:42] falls asleep +[1518-03-29 23:58] Guard #337 begins shift +[1518-04-07 00:54] falls asleep +[1518-06-28 23:53] Guard #89 begins shift +[1518-08-04 00:29] falls asleep +[1518-05-08 00:47] falls asleep +[1518-11-02 00:23] falls asleep +[1518-05-02 00:15] falls asleep +[1518-05-27 23:58] Guard #373 begins shift +[1518-09-29 00:19] falls asleep +[1518-08-25 00:45] wakes up +[1518-09-23 00:39] wakes up +[1518-09-14 00:15] falls asleep +[1518-04-24 23:50] Guard #2243 begins shift +[1518-07-01 00:39] wakes up +[1518-04-16 00:51] wakes up +[1518-07-30 00:28] falls asleep +[1518-09-12 23:58] Guard #1367 begins shift +[1518-07-08 00:37] falls asleep +[1518-06-23 00:13] falls asleep +[1518-10-22 00:38] falls asleep +[1518-09-14 00:52] falls asleep +[1518-06-02 00:24] wakes up +[1518-07-07 00:54] wakes up +[1518-06-27 00:32] wakes up +[1518-03-20 00:54] wakes up +[1518-08-27 23:56] Guard #3449 begins shift +[1518-08-22 00:45] wakes up +[1518-07-22 00:40] wakes up +[1518-09-03 00:28] wakes up +[1518-09-01 00:35] falls asleep +[1518-07-06 00:22] falls asleep +[1518-08-08 00:00] Guard #89 begins shift +[1518-07-17 00:50] falls asleep +[1518-10-04 00:56] wakes up +[1518-05-10 00:19] falls asleep +[1518-07-14 00:02] Guard #89 begins shift +[1518-10-24 23:58] Guard #2791 begins shift +[1518-04-14 00:58] wakes up +[1518-06-08 00:47] wakes up +[1518-03-27 00:38] wakes up +[1518-11-22 00:03] Guard #2243 begins shift +[1518-03-31 00:22] falls asleep +[1518-11-13 23:58] Guard #337 begins shift +[1518-04-18 00:22] falls asleep +[1518-04-10 00:58] wakes up +[1518-11-02 00:53] wakes up +[1518-10-30 00:40] wakes up +[1518-07-05 23:50] Guard #3119 begins shift +[1518-08-12 00:36] wakes up +[1518-04-18 23:52] Guard #2617 begins shift +[1518-09-17 00:04] Guard #2089 begins shift +[1518-05-31 00:03] Guard #2617 begins shift +[1518-10-18 00:10] falls asleep +[1518-04-05 00:43] falls asleep +[1518-10-11 00:32] wakes up +[1518-04-10 00:45] falls asleep +[1518-05-04 00:20] wakes up +[1518-06-11 00:25] falls asleep +[1518-08-13 00:58] wakes up +[1518-10-01 00:06] falls asleep +[1518-07-30 00:48] wakes up +[1518-07-12 00:54] wakes up +[1518-04-28 00:01] Guard #787 begins shift +[1518-11-16 00:31] falls asleep +[1518-08-08 00:28] wakes up +[1518-11-19 00:57] falls asleep +[1518-06-07 00:36] wakes up +[1518-03-28 00:45] wakes up +[1518-05-13 00:46] falls asleep +[1518-09-22 00:18] wakes up +[1518-04-29 23:57] Guard #1151 begins shift +[1518-08-15 00:57] wakes up +[1518-06-25 00:29] falls asleep +[1518-09-02 23:59] Guard #1973 begins shift +[1518-10-28 00:26] falls asleep +[1518-04-19 00:05] falls asleep +[1518-04-25 00:49] wakes up +[1518-10-08 23:48] Guard #1951 begins shift +[1518-07-18 00:01] wakes up +[1518-09-30 00:45] wakes up +[1518-09-15 00:30] wakes up +[1518-08-13 00:42] wakes up +[1518-05-16 00:03] Guard #499 begins shift +[1518-08-08 23:58] Guard #2617 begins shift +[1518-05-25 00:26] falls asleep +[1518-05-17 00:26] falls asleep +[1518-04-23 00:41] wakes up +[1518-10-23 23:53] Guard #1367 begins shift +[1518-07-25 23:57] Guard #337 begins shift +[1518-09-27 23:57] Guard #809 begins shift +[1518-11-11 00:54] falls asleep +[1518-09-07 23:59] Guard #499 begins shift +[1518-05-16 23:53] Guard #1973 begins shift +[1518-10-14 00:58] wakes up +[1518-05-17 00:00] falls asleep +[1518-09-09 23:56] Guard #3119 begins shift +[1518-04-28 00:30] wakes up +[1518-03-30 00:17] falls asleep +[1518-08-21 00:23] wakes up +[1518-04-06 00:55] wakes up +[1518-05-08 00:59] wakes up +[1518-07-11 00:16] wakes up +[1518-06-09 00:04] Guard #2341 begins shift +[1518-10-24 00:46] falls asleep +[1518-07-18 00:44] wakes up +[1518-09-05 23:57] Guard #631 begins shift +[1518-04-13 00:37] wakes up +[1518-03-18 00:59] wakes up +[1518-07-23 00:40] falls asleep +[1518-07-18 00:58] wakes up +[1518-11-03 00:33] falls asleep +[1518-04-22 00:10] falls asleep +[1518-07-05 00:01] Guard #89 begins shift +[1518-07-15 00:18] falls asleep +[1518-04-16 00:00] falls asleep +[1518-10-15 00:36] falls asleep +[1518-09-09 00:57] wakes up +[1518-04-26 00:00] Guard #787 begins shift +[1518-10-21 23:57] Guard #3449 begins shift +[1518-06-19 00:50] wakes up +[1518-03-18 00:35] falls asleep +[1518-10-26 00:04] Guard #787 begins shift +[1518-10-09 00:09] wakes up +[1518-04-28 00:40] falls asleep +[1518-11-03 00:03] Guard #2341 begins shift +[1518-08-03 00:53] falls asleep +[1518-10-29 00:47] wakes up +[1518-09-30 00:15] falls asleep +[1518-05-21 00:53] wakes up +[1518-05-03 00:05] falls asleep +[1518-06-05 00:59] wakes up +[1518-08-04 00:04] Guard #1367 begins shift +[1518-04-15 00:57] wakes up +[1518-05-02 00:54] wakes up +[1518-11-06 00:47] wakes up +[1518-05-18 00:49] wakes up +[1518-03-29 00:03] Guard #2341 begins shift +[1518-09-27 00:00] Guard #1973 begins shift +[1518-06-20 00:58] wakes up +[1518-06-23 00:39] wakes up +[1518-07-25 00:41] wakes up +[1518-03-26 00:03] Guard #337 begins shift +[1518-10-02 00:10] falls asleep +[1518-08-01 00:20] falls asleep +[1518-06-11 00:51] falls asleep +[1518-06-23 00:00] Guard #1951 begins shift +[1518-09-27 00:45] wakes up +[1518-09-05 00:53] falls asleep +[1518-11-20 00:42] wakes up +[1518-10-31 23:48] Guard #2617 begins shift +[1518-10-07 00:50] falls asleep +[1518-09-05 00:55] wakes up +[1518-08-29 00:53] wakes up +[1518-09-16 00:59] wakes up +[1518-07-14 00:19] wakes up +[1518-09-22 00:58] wakes up +[1518-06-23 00:43] falls asleep +[1518-07-15 00:15] wakes up +[1518-07-08 00:02] Guard #89 begins shift +[1518-07-11 00:48] wakes up +[1518-09-25 00:59] wakes up +[1518-05-23 00:36] falls asleep +[1518-03-22 00:04] Guard #2341 begins shift +[1518-09-06 00:41] wakes up +[1518-06-25 00:02] Guard #947 begins shift +[1518-05-16 00:54] wakes up +[1518-06-23 23:58] Guard #2791 begins shift +[1518-05-07 00:45] falls asleep +[1518-07-14 23:50] Guard #1973 begins shift +[1518-04-01 00:28] wakes up +[1518-10-11 00:41] wakes up +[1518-06-19 00:00] Guard #3449 begins shift +[1518-07-24 23:49] Guard #89 begins shift +[1518-05-30 00:58] wakes up +[1518-10-25 00:43] wakes up +[1518-05-04 00:07] falls asleep +[1518-10-05 00:00] Guard #809 begins shift +[1518-08-01 00:04] Guard #89 begins shift +[1518-07-30 00:00] Guard #89 begins shift +[1518-07-17 00:00] Guard #499 begins shift +[1518-07-06 00:38] wakes up +[1518-06-26 00:51] wakes up +[1518-09-28 00:27] falls asleep +[1518-06-09 00:31] wakes up +[1518-10-22 00:43] wakes up +[1518-10-31 00:41] falls asleep +[1518-06-14 00:04] falls asleep +[1518-07-19 00:38] wakes up +[1518-05-22 00:38] falls asleep +[1518-11-10 00:29] wakes up +[1518-10-23 00:05] falls asleep +[1518-06-16 00:38] wakes up +[1518-04-24 00:47] wakes up +[1518-07-23 00:03] Guard #631 begins shift +[1518-06-08 00:40] falls asleep +[1518-05-08 00:53] wakes up +[1518-09-04 00:38] wakes up +[1518-08-29 00:50] falls asleep +[1518-11-10 00:15] falls asleep +[1518-11-23 00:54] wakes up +[1518-11-05 00:36] falls asleep +[1518-10-04 00:02] Guard #2341 begins shift +[1518-04-06 00:00] Guard #1367 begins shift +[1518-07-17 23:46] Guard #2089 begins shift +[1518-06-15 00:44] wakes up +[1518-04-10 00:17] wakes up +[1518-08-31 00:32] falls asleep +[1518-05-03 00:30] wakes up +[1518-09-11 00:23] falls asleep +[1518-06-12 00:54] wakes up +[1518-11-08 23:50] Guard #1481 begins shift +[1518-08-31 00:59] wakes up +[1518-09-25 00:40] falls asleep +[1518-09-23 00:11] wakes up +[1518-06-06 00:57] wakes up +[1518-05-03 00:18] wakes up +[1518-09-22 00:24] falls asleep +[1518-09-06 00:50] falls asleep +[1518-05-01 00:46] falls asleep +[1518-05-07 00:46] wakes up +[1518-10-21 00:51] wakes up +[1518-05-08 00:34] wakes up +[1518-08-25 23:53] Guard #337 begins shift +[1518-08-04 00:19] wakes up +[1518-10-25 00:53] wakes up +[1518-09-26 00:53] wakes up +[1518-05-17 23:57] Guard #2089 begins shift +[1518-08-06 00:01] Guard #631 begins shift +[1518-07-04 00:43] wakes up +[1518-06-22 00:57] falls asleep +[1518-05-17 00:01] wakes up +[1518-05-14 00:19] wakes up +[1518-05-25 23:56] Guard #89 begins shift +[1518-08-11 00:44] wakes up +[1518-11-03 00:50] wakes up +[1518-06-10 00:03] Guard #631 begins shift +[1518-06-11 00:42] wakes up +[1518-07-09 00:03] Guard #3119 begins shift +[1518-04-02 00:34] falls asleep +[1518-08-20 00:00] Guard #3449 begins shift +[1518-06-13 00:00] Guard #3019 begins shift +[1518-07-17 00:57] wakes up +[1518-03-23 00:37] wakes up +[1518-07-08 00:50] wakes up +[1518-09-04 00:30] wakes up +[1518-05-25 00:35] wakes up +[1518-07-28 00:21] falls asleep +[1518-09-04 00:56] falls asleep +[1518-06-19 00:11] falls asleep +[1518-07-03 00:00] falls asleep +[1518-06-17 23:56] Guard #2341 begins shift +[1518-04-28 00:14] falls asleep +[1518-11-04 00:57] wakes up +[1518-11-04 00:11] falls asleep +[1518-09-15 00:41] falls asleep +[1518-07-23 23:59] Guard #1481 begins shift +[1518-11-06 23:58] Guard #3119 begins shift +[1518-10-31 00:22] falls asleep +[1518-04-04 00:59] wakes up +[1518-08-31 00:50] falls asleep +[1518-11-23 00:03] Guard #1481 begins shift +[1518-09-08 23:56] Guard #1973 begins shift +[1518-04-13 00:55] falls asleep +[1518-09-21 00:01] Guard #1973 begins shift +[1518-05-02 23:46] Guard #631 begins shift +[1518-09-11 00:00] Guard #2617 begins shift +[1518-09-22 23:49] Guard #2617 begins shift +[1518-09-01 23:58] Guard #2617 begins shift +[1518-11-10 00:52] wakes up +[1518-11-21 00:03] falls asleep +[1518-06-09 00:46] wakes up +[1518-11-18 00:37] wakes up +[1518-03-30 00:30] wakes up +[1518-08-09 00:34] wakes up +[1518-04-02 00:00] Guard #2791 begins shift +[1518-05-01 00:06] falls asleep +[1518-03-19 00:58] wakes up +[1518-08-19 00:30] falls asleep +[1518-06-07 00:54] falls asleep +[1518-11-01 00:58] wakes up +[1518-08-28 00:22] wakes up +[1518-09-16 00:09] falls asleep +[1518-03-21 00:44] wakes up +[1518-05-08 00:57] falls asleep +[1518-07-27 23:56] Guard #809 begins shift +[1518-05-19 00:53] falls asleep +[1518-10-12 00:37] falls asleep +[1518-09-24 00:51] wakes up +[1518-11-22 00:09] wakes up +[1518-09-13 00:23] wakes up +[1518-09-05 00:02] Guard #2341 begins shift +[1518-08-08 00:53] wakes up +[1518-07-22 00:12] falls asleep +[1518-11-16 00:59] wakes up +[1518-05-21 00:02] Guard #89 begins shift +[1518-03-23 00:45] falls asleep +[1518-04-04 00:55] falls asleep +[1518-10-25 00:57] falls asleep +[1518-07-31 00:52] wakes up +[1518-04-02 23:49] Guard #947 begins shift +[1518-04-18 00:17] wakes up +[1518-10-08 00:08] falls asleep +[1518-05-06 00:23] falls asleep +[1518-11-09 00:04] falls asleep +[1518-09-01 00:52] falls asleep +[1518-08-14 00:00] Guard #499 begins shift +[1518-07-11 00:20] falls asleep +[1518-03-26 00:40] falls asleep +[1518-06-01 23:58] Guard #337 begins shift +[1518-07-26 00:07] falls asleep +[1518-04-13 00:25] falls asleep +[1518-09-26 00:03] Guard #1973 begins shift +[1518-06-07 00:56] wakes up +[1518-06-21 00:22] falls asleep +[1518-11-12 00:55] wakes up +[1518-08-21 23:56] Guard #3449 begins shift +[1518-04-07 00:03] Guard #809 begins shift +[1518-10-01 00:43] wakes up +[1518-03-31 00:39] falls asleep +[1518-07-25 00:30] falls asleep +[1518-07-29 00:16] falls asleep +[1518-07-28 00:23] wakes up +[1518-07-27 00:00] Guard #2617 begins shift +[1518-06-04 00:55] wakes up +[1518-03-24 00:59] wakes up +[1518-10-29 00:56] falls asleep +[1518-06-10 00:07] falls asleep +[1518-08-29 00:01] Guard #3449 begins shift +[1518-09-09 00:37] falls asleep +[1518-03-23 23:58] Guard #787 begins shift +[1518-03-21 00:01] Guard #2089 begins shift +[1518-03-24 00:56] falls asleep +[1518-07-07 00:40] falls asleep +[1518-10-24 00:03] falls asleep +[1518-05-01 00:50] wakes up +[1518-11-14 00:52] wakes up +[1518-05-19 00:22] falls asleep +[1518-05-24 00:03] Guard #373 begins shift +[1518-10-22 00:55] wakes up +[1518-06-12 00:00] falls asleep +[1518-10-30 00:59] wakes up +[1518-08-30 00:02] Guard #2617 begins shift +[1518-10-24 00:23] wakes up +[1518-03-27 00:26] falls asleep +[1518-07-26 00:50] wakes up +[1518-08-06 00:45] falls asleep +[1518-06-22 00:59] wakes up +[1518-09-17 00:18] falls asleep +[1518-09-02 00:37] falls asleep +[1518-11-21 00:31] falls asleep +[1518-09-23 00:05] falls asleep +[1518-10-24 00:47] wakes up +[1518-06-06 00:45] falls asleep +[1518-05-09 00:54] wakes up +[1518-07-13 00:53] wakes up +[1518-06-15 23:50] Guard #3449 begins shift +[1518-08-03 00:46] wakes up +[1518-06-16 00:01] falls asleep +[1518-07-25 00:20] wakes up +[1518-09-11 00:56] wakes up +[1518-10-04 00:47] falls asleep +[1518-09-19 00:01] Guard #1481 begins shift +[1518-11-08 00:46] wakes up +[1518-06-09 00:36] falls asleep +[1518-08-24 00:01] falls asleep +[1518-08-21 00:56] wakes up +[1518-11-13 00:07] falls asleep +[1518-07-14 00:51] wakes up +[1518-10-15 00:41] wakes up +[1518-07-04 00:02] falls asleep +[1518-06-06 00:39] wakes up +[1518-06-20 00:06] falls asleep +[1518-06-08 00:15] falls asleep +[1518-07-15 00:37] wakes up +[1518-06-29 00:42] wakes up +[1518-04-04 00:51] wakes up +[1518-03-24 00:41] wakes up +[1518-09-21 23:56] Guard #1481 begins shift +[1518-11-18 00:01] falls asleep +[1518-07-19 00:44] falls asleep +[1518-08-14 00:58] wakes up +[1518-07-11 00:10] falls asleep +[1518-08-19 00:04] Guard #2341 begins shift +[1518-08-13 00:56] falls asleep +[1518-08-11 00:00] Guard #3019 begins shift +[1518-06-13 23:46] Guard #499 begins shift +[1518-04-17 00:04] Guard #3449 begins shift +[1518-11-20 00:17] falls asleep +[1518-05-13 23:59] Guard #1367 begins shift +[1518-09-20 00:42] wakes up +[1518-11-20 00:55] wakes up +[1518-10-09 00:44] wakes up +[1518-05-13 00:38] wakes up +[1518-06-30 00:54] wakes up +[1518-11-13 00:23] wakes up +[1518-03-24 00:06] falls asleep +[1518-05-13 00:12] falls asleep +[1518-05-09 00:35] falls asleep +[1518-03-26 00:52] falls asleep +[1518-06-25 00:07] falls asleep +[1518-11-03 00:55] falls asleep +[1518-06-15 00:01] Guard #3449 begins shift +[1518-05-18 00:44] falls asleep +[1518-04-19 00:38] wakes up +[1518-11-07 00:26] falls asleep +[1518-09-18 00:45] wakes up +[1518-05-14 00:16] falls asleep +[1518-11-12 00:44] falls asleep +[1518-09-19 00:38] falls asleep +[1518-08-03 00:56] wakes up +[1518-04-27 00:44] falls asleep +[1518-04-22 00:00] Guard #947 begins shift +[1518-08-03 00:03] Guard #2243 begins shift +[1518-10-30 00:22] falls asleep +[1518-03-25 00:58] wakes up +[1518-08-28 00:18] falls asleep +[1518-05-10 00:43] wakes up +[1518-07-07 00:27] falls asleep +[1518-06-26 00:18] wakes up +[1518-03-21 00:58] wakes up +[1518-07-10 00:48] falls asleep +[1518-10-31 00:44] wakes up +[1518-04-23 00:19] falls asleep +[1518-09-20 00:04] Guard #499 begins shift +[1518-10-08 00:41] wakes up +[1518-08-05 00:45] falls asleep +[1518-04-25 00:35] falls asleep +[1518-09-17 00:57] wakes up +[1518-10-19 00:09] falls asleep +[1518-09-06 23:50] Guard #2791 begins shift +[1518-11-20 00:47] falls asleep +[1518-07-18 23:58] Guard #499 begins shift +[1518-08-21 00:12] falls asleep +[1518-09-13 00:39] wakes up +[1518-11-07 00:23] wakes up +[1518-08-23 23:47] Guard #1481 begins shift +[1518-10-31 00:00] Guard #89 begins shift +[1518-07-29 00:13] wakes up +[1518-04-20 23:46] Guard #1481 begins shift +[1518-03-22 00:18] falls asleep +[1518-11-06 00:03] Guard #337 begins shift +[1518-07-27 00:08] falls asleep +[1518-05-12 00:35] falls asleep +[1518-05-18 00:20] falls asleep +[1518-04-14 00:41] falls asleep +[1518-08-06 00:33] wakes up +[1518-04-07 00:42] wakes up +[1518-09-18 00:58] wakes up +[1518-03-27 00:35] falls asleep +[1518-08-30 00:22] falls asleep +[1518-07-18 00:56] falls asleep +[1518-05-01 23:56] Guard #2791 begins shift +[1518-06-27 23:46] Guard #1973 begins shift +[1518-06-26 00:49] falls asleep +[1518-06-21 00:41] wakes up +[1518-05-06 00:03] wakes up +[1518-07-04 00:14] wakes up +[1518-04-07 23:56] Guard #1951 begins shift +[1518-07-27 00:54] wakes up +[1518-06-26 00:37] falls asleep +[1518-06-30 00:52] falls asleep +[1518-10-27 00:50] wakes up +[1518-10-23 00:50] wakes up +[1518-06-30 00:29] wakes up +[1518-05-07 00:51] falls asleep +[1518-10-24 00:35] falls asleep +[1518-09-03 00:12] falls asleep +[1518-08-10 00:32] falls asleep +[1518-08-07 00:33] falls asleep +[1518-10-08 00:22] falls asleep +[1518-08-16 00:16] falls asleep +[1518-03-25 00:26] falls asleep +[1518-05-22 00:04] Guard #3449 begins shift +[1518-08-26 23:58] Guard #787 begins shift +[1518-05-26 00:55] wakes up +[1518-09-15 00:13] falls asleep +[1518-09-06 00:38] falls asleep +[1518-04-07 00:37] falls asleep +[1518-06-28 00:59] wakes up +[1518-05-07 23:47] Guard #1367 begins shift +[1518-03-21 00:54] falls asleep +[1518-05-09 00:49] wakes up +[1518-08-01 23:57] Guard #1481 begins shift +[1518-05-08 00:02] falls asleep +[1518-08-02 00:57] wakes up +[1518-04-21 00:05] falls asleep +[1518-09-14 00:01] Guard #1951 begins shift +[1518-04-05 00:56] wakes up +[1518-06-27 00:49] falls asleep +[1518-07-15 00:01] falls asleep +[1518-08-31 23:59] Guard #809 begins shift +[1518-08-09 23:56] Guard #809 begins shift +[1518-04-11 00:19] falls asleep +[1518-11-14 00:49] falls asleep +[1518-04-19 23:57] Guard #3067 begins shift +[1518-03-28 00:12] falls asleep +[1518-10-27 00:02] Guard #631 begins shift +[1518-07-14 00:25] falls asleep +[1518-04-09 00:04] Guard #2617 begins shift +[1518-10-05 00:44] wakes up +[1518-08-13 00:03] Guard #439 begins shift +[1518-08-23 00:13] falls asleep +[1518-10-08 00:09] wakes up +[1518-08-26 00:54] wakes up +[1518-09-18 00:38] falls asleep +[1518-07-11 23:59] Guard #499 begins shift +[1518-10-25 00:07] falls asleep +[1518-06-10 00:53] wakes up +[1518-07-02 00:20] falls asleep +[1518-11-16 00:47] falls asleep +[1518-11-15 00:27] falls asleep +[1518-08-25 00:20] falls asleep +[1518-05-30 00:37] falls asleep +[1518-09-10 00:26] falls asleep +[1518-08-17 00:16] wakes up +[1518-10-15 00:44] falls asleep +[1518-10-05 00:38] falls asleep +[1518-03-26 00:53] wakes up +[1518-11-15 00:58] wakes up +[1518-10-13 23:56] Guard #947 begins shift +[1518-10-14 23:58] Guard #3449 begins shift +[1518-05-10 23:59] Guard #631 begins shift +[1518-08-12 00:11] falls asleep +[1518-03-31 00:25] wakes up +[1518-06-05 00:15] falls asleep +[1518-09-07 00:00] falls asleep +[1518-05-11 00:48] wakes up +[1518-09-03 00:53] wakes up +[1518-05-19 00:00] Guard #439 begins shift +[1518-04-13 23:59] Guard #499 begins shift +[1518-08-22 23:56] Guard #1481 begins shift +[1518-10-14 00:06] falls asleep +[1518-04-23 23:56] Guard #947 begins shift +[1518-04-15 00:44] wakes up +[1518-09-12 00:50] wakes up +[1518-08-13 00:30] falls asleep +[1518-07-28 23:52] Guard #809 begins shift +[1518-11-08 00:05] falls asleep +[1518-10-13 00:50] wakes up +[1518-10-03 00:01] Guard #2791 begins shift +[1518-04-26 00:16] falls asleep +[1518-05-20 00:22] falls asleep +[1518-04-18 00:03] falls asleep +[1518-10-01 00:00] Guard #787 begins shift +[1518-09-25 00:42] wakes up +[1518-06-07 00:26] falls asleep +[1518-09-04 00:00] Guard #2341 begins shift +[1518-07-10 00:33] wakes up +[1518-10-18 00:49] falls asleep +[1518-06-28 00:04] falls asleep +[1518-11-21 00:18] wakes up +[1518-07-23 00:57] wakes up +[1518-08-20 00:35] falls asleep +[1518-06-19 00:25] wakes up +[1518-04-21 00:14] wakes up +[1518-06-26 23:59] Guard #337 begins shift +[1518-06-08 00:01] Guard #499 begins shift +[1518-07-12 00:33] falls asleep +[1518-09-09 00:41] wakes up +[1518-04-17 23:49] Guard #89 begins shift +[1518-06-11 23:53] Guard #2089 begins shift +[1518-04-26 23:58] Guard #3019 begins shift +[1518-08-10 00:52] wakes up +[1518-11-19 00:47] wakes up +[1518-06-27 00:19] falls asleep +[1518-09-24 00:27] falls asleep +[1518-07-09 00:36] wakes up +[1518-08-15 00:00] Guard #337 begins shift +[1518-05-18 00:32] wakes up +[1518-07-25 00:01] falls asleep +[1518-06-05 00:00] Guard #337 begins shift +[1518-10-15 23:58] Guard #439 begins shift +[1518-09-04 00:57] wakes up +[1518-04-10 00:37] wakes up +[1518-07-04 00:48] falls asleep +[1518-09-13 00:20] falls asleep +[1518-11-01 00:34] falls asleep +[1518-06-29 23:54] Guard #337 begins shift +[1518-08-07 00:26] wakes up +[1518-05-08 23:56] Guard #2089 begins shift +[1518-04-02 00:59] wakes up +[1518-06-11 00:03] Guard #1481 begins shift +[1518-10-19 00:50] wakes up +[1518-06-06 00:51] falls asleep +[1518-11-06 00:38] falls asleep +[1518-03-29 00:42] falls asleep +[1518-08-12 00:00] Guard #1973 begins shift +[1518-08-31 00:02] Guard #439 begins shift +[1518-08-09 00:09] falls asleep +[1518-04-03 00:44] wakes up +[1518-05-07 00:00] Guard #631 begins shift +[1518-03-27 00:49] wakes up +[1518-10-10 00:59] wakes up +[1518-06-04 00:21] falls asleep +[1518-03-23 00:51] wakes up +[1518-08-18 00:52] wakes up +[1518-11-14 00:40] wakes up +[1518-06-25 23:50] Guard #631 begins shift +[1518-10-05 00:20] wakes up +[1518-05-11 00:32] falls asleep +[1518-06-19 00:42] falls asleep +[1518-09-12 00:01] Guard #2617 begins shift +[1518-08-30 00:24] wakes up +[1518-10-15 00:47] wakes up +[1518-05-17 00:55] wakes up +[1518-04-07 00:56] wakes up +[1518-10-16 00:43] wakes up +[1518-08-17 23:57] Guard #337 begins shift +[1518-08-07 00:00] Guard #2243 begins shift +[1518-06-11 00:58] wakes up +[1518-05-12 00:58] wakes up +[1518-10-05 00:09] falls asleep +[1518-05-07 00:56] wakes up +[1518-10-08 00:56] wakes up +[1518-03-21 00:32] falls asleep +[1518-11-20 00:03] Guard #1973 begins shift +[1518-05-05 23:53] Guard #787 begins shift +[1518-08-11 00:41] falls asleep +[1518-05-30 00:02] Guard #631 begins shift +[1518-10-10 00:55] falls asleep +[1518-06-03 00:40] wakes up +[1518-03-29 00:46] wakes up +[1518-11-10 00:03] Guard #787 begins shift +[1518-08-21 00:44] falls asleep +[1518-06-10 00:34] falls asleep +[1518-06-20 00:03] Guard #809 begins shift +[1518-07-21 00:04] Guard #373 begins shift +[1518-05-06 00:47] wakes up +[1518-04-10 00:35] falls asleep +[1518-04-05 00:37] wakes up +[1518-06-19 00:32] wakes up +[1518-04-04 00:22] wakes up +[1518-06-30 00:04] falls asleep +[1518-04-25 00:05] falls asleep +[1518-09-15 23:57] Guard #2243 begins shift +[1518-07-10 00:10] falls asleep +[1518-10-21 00:02] falls asleep +[1518-10-20 00:01] Guard #1151 begins shift +[1518-03-27 00:31] wakes up +[1518-04-22 23:59] Guard #1367 begins shift +[1518-11-09 00:37] wakes up +[1518-10-11 00:35] falls asleep +[1518-10-28 00:42] wakes up +[1518-11-21 00:04] wakes up +[1518-08-15 00:13] falls asleep +[1518-10-13 00:04] Guard #1973 begins shift +[1518-04-09 00:47] falls asleep +[1518-11-17 00:37] falls asleep +[1518-03-31 23:58] Guard #499 begins shift +[1518-05-10 00:03] Guard #3449 begins shift +[1518-11-21 00:07] falls asleep +[1518-09-04 00:18] falls asleep +[1518-09-28 00:51] falls asleep +[1518-05-19 23:58] Guard #2089 begins shift +[1518-04-09 23:51] Guard #809 begins shift +[1518-07-28 00:53] wakes up +[1518-10-06 00:16] falls asleep +[1518-03-23 00:25] falls asleep +[1518-07-01 00:29] falls asleep +[1518-04-05 00:10] falls asleep +[1518-08-02 00:43] falls asleep +[1518-06-24 00:14] falls asleep +[1518-04-09 00:26] wakes up +[1518-06-29 00:05] falls asleep +[1518-06-01 00:35] falls asleep +[1518-06-17 00:57] wakes up +[1518-09-13 00:30] falls asleep +[1518-09-15 00:00] Guard #337 begins shift +[1518-05-19 00:39] wakes up +[1518-05-09 00:52] falls asleep +[1518-10-17 00:04] Guard #1151 begins shift +[1518-10-06 23:57] Guard #809 begins shift +[1518-08-04 00:15] falls asleep +[1518-11-19 00:00] Guard #2791 begins shift +[1518-04-03 00:05] falls asleep +[1518-08-17 00:52] wakes up +[1518-04-19 00:21] falls asleep +[1518-10-18 00:51] wakes up +[1518-10-11 00:02] Guard #1951 begins shift +[1518-06-06 00:02] Guard #2791 begins shift +[1518-10-07 00:52] wakes up +[1518-11-08 00:35] falls asleep +[1518-09-23 00:14] falls asleep +[1518-03-23 00:04] Guard #1481 begins shift +[1518-06-19 00:29] falls asleep +[1518-05-14 23:47] Guard #947 begins shift +[1518-09-06 00:57] wakes up +[1518-10-03 00:14] falls asleep +[1518-06-04 00:00] Guard #787 begins shift +[1518-10-05 23:58] Guard #787 begins shift +[1518-09-11 00:39] falls asleep +[1518-04-26 00:56] wakes up diff --git a/problems/day04.html b/problems/day04.html new file mode 100644 index 0000000..1a137b9 --- /dev/null +++ b/problems/day04.html @@ -0,0 +1,161 @@ + + + + +Day 4 - Advent of Code 2018 + + + + + + + +

Advent of Code

Neil Smith (AoC++) 8*

   var y=2018;

+ + + +
+

--- Day 4: Repose Record ---

You've sneaked into another supply closet - this time, it's across from the prototype suit manufacturing lab. You need to sneak inside and fix the issues with the suit, but there's a guard stationed outside the lab, so this is as close as you can safely get.

+

As you search the closet for anything that might help, you discover that you're not the first person to want to sneak in. Covering the walls, someone has spent an hour starting every midnight for the past few months secretly observing this guard post! They've been writing down the ID of the one guard on duty that night - the Elves seem to have decided that one guard was enough for the overnight shift - as well as when they fall asleep or wake up while at their post (your puzzle input).

+

For example, consider the following records, which have already been organized into chronological order:

+
[1518-11-01 00:00] Guard #10 begins shift
+[1518-11-01 00:05] falls asleep
+[1518-11-01 00:25] wakes up
+[1518-11-01 00:30] falls asleep
+[1518-11-01 00:55] wakes up
+[1518-11-01 23:58] Guard #99 begins shift
+[1518-11-02 00:40] falls asleep
+[1518-11-02 00:50] wakes up
+[1518-11-03 00:05] Guard #10 begins shift
+[1518-11-03 00:24] falls asleep
+[1518-11-03 00:29] wakes up
+[1518-11-04 00:02] Guard #99 begins shift
+[1518-11-04 00:36] falls asleep
+[1518-11-04 00:46] wakes up
+[1518-11-05 00:03] Guard #99 begins shift
+[1518-11-05 00:45] falls asleep
+[1518-11-05 00:55] wakes up
+
+

Timestamps are written using year-month-day hour:minute format. The guard falling asleep or waking up is always the one whose shift most recently started. Because all asleep/awake times are during the midnight hour (00:00 - 00:59), only the minute portion (00 - 59) is relevant for those events.

+

Visually, these records show that the guards are asleep at these times:

+
Date   ID   Minute
+            000000000011111111112222222222333333333344444444445555555555
+            012345678901234567890123456789012345678901234567890123456789
+11-01  #10  .....####################.....#########################.....
+11-02  #99  ........................................##########..........
+11-03  #10  ........................#####...............................
+11-04  #99  ....................................##########..............
+11-05  #99  .............................................##########.....
+
+

The columns are Date, which shows the month-day portion of the relevant day; ID, which shows the guard on duty that day; and Minute, which shows the minutes during which the guard was asleep within the midnight hour. (The Minute column's header shows the minute's ten's digit in the first row and the one's digit in the second row.) Awake is shown as ., and asleep is shown as #.

+

Note that guards count as asleep on the minute they fall asleep, and they count as awake on the minute they wake up. For example, because Guard #10 wakes up at 00:25 on 1518-11-01, minute 25 is marked as awake.

+

If you can figure out the guard most likely to be asleep at a specific time, you might be able to trick that guard into working tonight so you can have the best chance of sneaking in. You have two strategies for choosing the best guard/minute combination.

+

Strategy 1: Find the guard that has the most minutes asleep. What minute does that guard spend asleep the most?

+

In the example above, Guard #10 spent the most minutes asleep, a total of 50 minutes (20+25+5), while Guard #99 only slept for a total of 30 minutes (10+10+10). Guard #10 was asleep most during minute 24 (on two days, whereas any other minute the guard was asleep was only seen on one day).

+

While this example listed the entries in chronological order, your entries are in the order you found them. You'll need to organize them before they can be analyzed.

+

What is the ID of the guard you chose multiplied by the minute you chose? (In the above example, the answer would be 10 * 24 = 240.)

+
+

Your puzzle answer was 21956.

--- Part Two ---

Strategy 2: Of all guards, which guard is most frequently asleep on the same minute?

+

In the example above, Guard #99 spent minute 45 asleep more than any other guard or minute - three times in total. (In all other cases, any guard spent any minute asleep at most twice.)

+

What is the ID of the guard you chose multiplied by the minute you chose? (In the above example, the answer would be 99 * 45 = 4455.)

+
+

Your puzzle answer was 134511.

Both parts of this puzzle are complete! They provide two gold stars: **

+

At this point, you should return to your advent calendar and try another puzzle.

+

If you still want to see it, you can get your puzzle input.

+

You can also this puzzle.

+
+ + + + + + \ No newline at end of file diff --git a/src/advent04/advent04.hs b/src/advent04/advent04.hs new file mode 100644 index 0000000..d1edcba --- /dev/null +++ b/src/advent04/advent04.hs @@ -0,0 +1,161 @@ +{-# LANGUAGE OverloadedStrings #-} + +import Data.List +-- import Data.Tuple (swap) + +import Data.Text (Text) +import qualified Data.Text.IO as TIO + +import Data.Void (Void) + +import Text.Megaparsec +import Text.Megaparsec.Char +import qualified Text.Megaparsec.Char.Lexer as L +import qualified Control.Applicative as CA + +import Data.Time +-- import Data.Time.LocalTime + +import qualified Data.Set as S +import qualified Data.Map.Strict as M + +type GuardId = Integer + +data LogEvent = Arrives GuardId | Sleeps | Wakes deriving (Eq, Show, Ord) +data LogEntry = LogEntry { _logTime :: UTCTime , _logEvent :: LogEvent } deriving (Eq, Show, Ord) + +data GuardState = Asleep UTCTime | Awake +data LogTracker = LogTracker {_currentGuard :: GuardId, _currentState :: GuardState } + +type GuardActivity = S.Set (UTCTime, GuardId) +type Guards = S.Set GuardId +-- type Minutes = S.Set Int +type GuardSleepDuration = M.Map GuardId Int +type SleepFrequency = M.Map Int Int -- key = minute, value = times spent asleep +type GuardSleepFrequency = M.Map (GuardId, Int) Int -- key = (guardID, minute), value = times spent asleep + + + +main :: IO () +main = do + text <- TIO.readFile "data/advent04.txt" + let guardLog = sort $ successfulParse text + let activity = buildActivity guardLog + print $ part1 activity + print $ part2 activity + +part1 :: GuardActivity -> Int +part1 activity = (fromIntegral sg) * mostAsleep + where sd = sleepDurations activity + sg = sleepiestGuard sd + sga = guardActivity sg activity + sgf = sleepFrequency sga + mostAsleep = keyOfMaxValue sgf + +part2 :: GuardActivity -> Int +part2 activity = (fromIntegral g) * m + where gids = guardsOf activity + sleepTimes = M.fromSet (\gid -> guardSleepFrequency gid activity) gids + gsfs = M.foldrWithKey' rekeySleep M.empty sleepTimes + (g, m) = keyOfMaxValue gsfs + +rekeySleep :: GuardId -> SleepFrequency -> GuardSleepFrequency -> GuardSleepFrequency +rekeySleep gid sleepFreq guardSleepFreq = M.foldrWithKey' (\m f gsf -> M.insert (gid, m) f gsf) guardSleepFreq sleepFreq + + + +buildActivity :: [LogEntry] -> GuardActivity +buildActivity guardLog = snd $ foldl' processLogEntry' (initialTracker, S.empty) guardLog + where initialTracker = LogTracker {_currentGuard = 0, _currentState = Awake} + processLogEntry' (tracker, activity) entry = processLogEntry (_logEvent entry) (_logTime entry) tracker activity + +processLogEntry :: LogEvent -> UTCTime -> LogTracker -> GuardActivity -> (LogTracker, GuardActivity) +processLogEntry (Arrives gid) _ _ activity = (LogTracker {_currentGuard = gid, _currentState = Awake}, activity) +processLogEntry Sleeps time tracker activity = (tracker {_currentState = Asleep time}, activity) +processLogEntry Wakes time tracker activity = (tracker {_currentState = Awake}, activity') + where Asleep sleepTime = _currentState tracker + guardId = _currentGuard tracker + sleepMinutes = unfoldr unfoldF sleepTime + unfoldF now = if now >= time then Nothing + else Just ((now, guardId), addUTCTime 60 now) + activity' = S.union activity $ S.fromList sleepMinutes + +guardsOf :: GuardActivity -> Guards +guardsOf = S.map snd + +-- minutesOf :: GuardActivity -> Minutes +-- minutesOf activity = S.map (toMinutes . fst) activity + +toMinutes :: UTCTime -> Int +toMinutes = todMin . timeToTimeOfDay . utctDayTime + +totalSleepDuration :: GuardId -> GuardActivity -> Int +totalSleepDuration gid activity = S.size $ guardActivity gid activity + +-- all activity of one guard +guardActivity :: GuardId -> GuardActivity -> GuardActivity +guardActivity gid activity = S.filter (\(_, g) -> g == gid) activity + +sleepDurations :: GuardActivity -> GuardSleepDuration +sleepDurations activity = M.fromSet guardSleepDuration gids + where gids = guardsOf activity + guardSleepDuration gid = totalSleepDuration gid activity + + +sleepiestGuard :: GuardSleepDuration -> GuardId +sleepiestGuard = keyOfMaxValue + + +keyOfMaxValue :: Ord b => M.Map a b -> a +keyOfMaxValue m = fst $ M.foldrWithKey mergeKV (M.findMin m) m + where mergeKV k v (bestK, bestV) = + if v > bestV then (k, v) else (bestK, bestV) + + +sleepFrequency :: GuardActivity -> SleepFrequency +sleepFrequency activity = S.foldl' updateSF M.empty activity + where updateSF m (t, _) = M.insert (toMinutes t) ((M.findWithDefault 0 (toMinutes t) m) + 1) m + +guardSleepFrequency :: GuardId -> GuardActivity -> SleepFrequency +guardSleepFrequency gid activity = sleepFrequency $ guardActivity gid activity + + +-- Parse the input file + +type Parser = Parsec Void Text + +sc :: Parser () +sc = L.space (skipSome spaceChar) CA.empty CA.empty +-- sc = L.space (skipSome (char ' ')) CA.empty CA.empty + +lexeme = L.lexeme sc +integer = lexeme L.decimal +symb = L.symbol sc + +openP = symb "[" +closeP = symb "]" +dashP = symb "-" +colonP = symb ":" + + +logFileP = many logEntryP +logEntryP = logify <$> timeStampP <*> eventP + where logify t e = LogEntry {_logTime = t, _logEvent = e} + + +eventP = arrivesP <|> sleepsP <|> wakesP +arrivesP = Arrives <$> ((symb "Guard #") *> integer <* (symb "begins shift")) +sleepsP = Sleeps <$ (symb "falls asleep") +wakesP = Wakes <$ (symb "wakes up") + +-- [1518-10-25 00:48] +timeStampP = between openP closeP timeStampInnerP +timeStampInnerP = dtify <$> integer <* dashP <*> integer <* dashP <*> integer <*> integer <* colonP <*> integer + where dtify y mo d h mi = UTCTime (fromGregorian y (fromIntegral mo) (fromIntegral d)) (tify h mi) + tify h mi = secondsToDiffTime ((h * 60) + mi) * 60 + +successfulParse :: Text -> [LogEntry] +successfulParse input = + case parse logFileP "input" input of + Left _error -> [] -- TIO.putStr $ T.pack $ parseErrorPretty err + Right guardLog -> guardLog \ No newline at end of file -- 2.34.1