aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/2017/day13/aoc.cpp16
-rw-r--r--src/2017/day14/README.md28
-rw-r--r--test/test_2017.cpp4
3 files changed, 45 insertions, 3 deletions
diff --git a/src/2017/day13/aoc.cpp b/src/2017/day13/aoc.cpp
index bab6825..cb7bf1d 100644
--- a/src/2017/day13/aoc.cpp
+++ b/src/2017/day13/aoc.cpp
@@ -2,6 +2,15 @@
namespace aoc2017 {
+bool delay_at(int t, const std::vector<scanner>& vs) {
+ for (auto& s : vs) {
+ if (s.at_level(s.depth + t) == 0) {
+ return false;
+ }
+ }
+ return true;
+}
+
std::pair<int64_t, int64_t> day13(line_view file) {
std::vector<scanner> vs;
per_line(file, [&vs](line_view lv) {
@@ -17,9 +26,14 @@ std::pair<int64_t, int64_t> day13(line_view file) {
}
}
+ int delay{0};
+ while (!delay_at(delay, vs)) {
+ delay++;
+ }
+
// for (auto& s: vs) {
// s.print();
// }
- return {severity, 0};
+ return {severity, delay};
}
} // namespace aoc2017
diff --git a/src/2017/day14/README.md b/src/2017/day14/README.md
index e69de29..301e2cb 100644
--- a/src/2017/day14/README.md
+++ b/src/2017/day14/README.md
@@ -0,0 +1,28 @@
+--- Day 14: Disk Defragmentation ---
+Suddenly, a scheduled job activates the system's disk defragmenter. Were the situation different, you might sit and watch it for a while, but today, you just don't have that kind of time. It's soaking up valuable system resources that are needed elsewhere, and so the only option is to help it finish its task as soon as possible.
+
+The disk in question consists of a 128x128 grid; each square of the grid is either free or used. On this disk, the state of the grid is tracked by the bits in a sequence of knot hashes.
+
+A total of 128 knot hashes are calculated, each corresponding to a single row in the grid; each hash contains 128 bits which correspond to individual grid squares. Each bit of a hash indicates whether that square is free (0) or used (1).
+
+The hash inputs are a key string (your puzzle input), a dash, and a number from 0 to 127 corresponding to the row. For example, if your key string were flqrgnkx, then the first row would be given by the bits of the knot hash of flqrgnkx-0, the second row from the bits of the knot hash of flqrgnkx-1, and so on until the last row, flqrgnkx-127.
+
+The output of a knot hash is traditionally represented by 32 hexadecimal digits; each of these digits correspond to 4 bits, for a total of 4 * 32 = 128 bits. To convert to bits, turn each hexadecimal digit to its equivalent binary value, high-bit first: 0 becomes 0000, 1 becomes 0001, e becomes 1110, f becomes 1111, and so on; a hash that begins with a0c2017... in hexadecimal would begin with 10100000110000100000000101110000... in binary.
+
+Continuing this process, the first 8 rows and columns for key flqrgnkx appear as follows, using # to denote used squares, and . to denote free ones:
+
+##.#.#..-->
+.#.#.#.#
+....#.#.
+#.#.##.#
+.##.#...
+##..#..#
+.#...#..
+##.#.##.-->
+| |
+V V
+In this example, 8108 squares are used across the entire 128x128 grid.
+
+Given your actual key string, how many squares are used?
+
+Your puzzle input is oundnydw.
diff --git a/test/test_2017.cpp b/test/test_2017.cpp
index db8d5b9..d7923b9 100644
--- a/test/test_2017.cpp
+++ b/test/test_2017.cpp
@@ -142,11 +142,11 @@ TEST_CASE("Packet Scanners", "[2017]") {
line_view lv = load_file("../src/2017/day13/input");
auto p = aoc2017::day13(lv);
REQUIRE(2384 == p.first);
- REQUIRE(0 == p.second);
+ REQUIRE(3921270 == p.second);
}
-TEST_CASE("", "[2017]") {
+TEST_CASE("Disk Defragmentation", "[2017]") {
line_view lv = load_file("../src/2017/day14/input");
auto p = aoc2017::day14(lv);
REQUIRE(0 == p.first);