aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkaiwu <kaiwu2004@gmail.com>2022-12-05 16:05:02 +0800
committerkaiwu <kaiwu2004@gmail.com>2022-12-05 16:05:02 +0800
commit2f828ddfb1f649f8ed53291bdaf9457c2f633f75 (patch)
treecb50b1edcd56cd7895fd71e8c6be2cbc0e1a75ef
parentc2820ed7b706a580bc60a74a0d2af806ca57f501 (diff)
downloadadvent-of-code-2f828ddfb1f649f8ed53291bdaf9457c2f633f75.tar.gz
advent-of-code-2f828ddfb1f649f8ed53291bdaf9457c2f633f75.zip
2022 day5
-rw-r--r--src/2020/day9/README.md30
-rw-r--r--src/2020/day9/aoc.cpp62
-rw-r--r--src/2020/day9/aoc.h2
-rw-r--r--src/2022/day5/README.md94
-rw-r--r--src/2022/day5/aoc.cpp21
-rw-r--r--src/2022/day5/aoc.h116
-rw-r--r--src/2022/day5/input511
-rw-r--r--test/test_2020.cpp7
-rw-r--r--test/test_2022.cpp9
9 files changed, 844 insertions, 8 deletions
diff --git a/src/2020/day9/README.md b/src/2020/day9/README.md
index e75d0d9..1beb6ba 100644
--- a/src/2020/day9/README.md
+++ b/src/2020/day9/README.md
@@ -44,3 +44,33 @@ In this example, after the 5-number preamble, almost every number is the sum of
The first step of attacking the weakness in the XMAS data is to find the first number in the list (after the preamble) which is not the sum of two of the 25 numbers before it. What is the first number that does not have this property?
+--- Part Two ---
+The final step in breaking the XMAS encryption relies on the invalid number you just found: you must find a contiguous set of at least two numbers in your list which sum to the invalid number from step 1.
+
+Again consider the above example:
+
+35
+20
+15
+25
+47
+40
+62
+55
+65
+95
+102
+117
+150
+182
+127
+219
+299
+277
+309
+576
+In this list, adding up all of the numbers from 15 through 40 produces the invalid number from step 1, 127. (Of course, the contiguous set of numbers in your actual list might be much longer.)
+
+To find the encryption weakness, add together the smallest and largest number in this contiguous range; in this example, these are 15 and 47, producing 62.
+
+What is the encryption weakness in your XMAS-encrypted list of numbers?
diff --git a/src/2020/day9/aoc.cpp b/src/2020/day9/aoc.cpp
index 849bad9..c7a826f 100644
--- a/src/2020/day9/aoc.cpp
+++ b/src/2020/day9/aoc.cpp
@@ -1,5 +1,67 @@
#include "aoc.h"
+#include <set>
namespace aoc2020 {
+static int numbers[1000] = {0};
+
+static int get_number(const char* p) {
+ int d{0};
+ while (*p >= '0' && *p <= '9') {
+ d = d * 10 + *p - '0';
+ p++;
+ }
+ return d;
+}
+
+bool check25(int i, int* weak) {
+ std::set<int> si;
+ for (int x = i - 25; x < i; x++) {
+ si.insert(numbers[x]);
+ }
+ for (int x = i - 25; x < i; x++) {
+ int y = numbers[i] - numbers[x];
+ if (si.find(y) != si.end()) {
+ return true;
+ }
+ }
+
+ *weak = numbers[i];
+ return false;
+}
+
+bool check_contiguous(int i, int* end, int target) {
+ return false;
+}
+
+static void minmax(int x, int y, int* min, int* max) {
+
+}
+
+std::pair<int, int> day9(line_view file) {
+ int i{0};
+ per_line(file, [&i](line_view lv){
+ numbers[i++] = get_number(lv.line);
+ return true;
+ });
+
+ int weak{0};
+ int pos{0};
+ for (int i = 25; i < 1000; i++) {
+ if (!check25(i, &weak)) {
+ pos = i;
+ break;
+ }
+ }
+
+ int e{0};
+ int min{INT32_MAX}, max{INT32_MIN};
+ for (int i = 0; i < pos; i++) {
+ if (check_contiguous(i, &e, weak)) {
+ minmax(i, e, &min, &max);
+ }
+ }
+
+ return {weak, min + max};
+}
}
diff --git a/src/2020/day9/aoc.h b/src/2020/day9/aoc.h
index c5ad3d1..9dcbaac 100644
--- a/src/2020/day9/aoc.h
+++ b/src/2020/day9/aoc.h
@@ -2,5 +2,5 @@
#include "common.h"
namespace aoc2020 {
-
+std::pair<int, int> day9(line_view file);
}
diff --git a/src/2022/day5/README.md b/src/2022/day5/README.md
index e69de29..65fb8af 100644
--- a/src/2022/day5/README.md
+++ b/src/2022/day5/README.md
@@ -0,0 +1,94 @@
+--- Day 5: Supply Stacks ---
+The expedition can depart as soon as the final supplies have been unloaded from the ships. Supplies are stored in stacks of marked crates, but because the needed supplies are buried under many other crates, the crates need to be rearranged.
+
+The ship has a giant cargo crane capable of moving crates between stacks. To ensure none of the crates get crushed or fall over, the crane operator will rearrange them in a series of carefully-planned steps. After the crates are rearranged, the desired crates will be at the top of each stack.
+
+The Elves don't want to interrupt the crane operator during this delicate procedure, but they forgot to ask her which crate will end up where, and they want to be ready to unload them as soon as possible so they can embark.
+
+They do, however, have a drawing of the starting stacks of crates and the rearrangement procedure (your puzzle input). For example:
+
+ [D]
+[N] [C]
+[Z] [M] [P]
+ 1 2 3
+
+move 1 from 2 to 1
+move 3 from 1 to 3
+move 2 from 2 to 1
+move 1 from 1 to 2
+In this example, there are three stacks of crates. Stack 1 contains two crates: crate Z is on the bottom, and crate N is on top. Stack 2 contains three crates; from bottom to top, they are crates M, C, and D. Finally, stack 3 contains a single crate, P.
+
+Then, the rearrangement procedure is given. In each step of the procedure, a quantity of crates is moved from one stack to a different stack. In the first step of the above rearrangement procedure, one crate is moved from stack 2 to stack 1, resulting in this configuration:
+
+[D]
+[N] [C]
+[Z] [M] [P]
+ 1 2 3
+In the second step, three crates are moved from stack 1 to stack 3. Crates are moved one at a time, so the first crate to be moved (D) ends up below the second and third crates:
+
+ [Z]
+ [N]
+ [C] [D]
+ [M] [P]
+ 1 2 3
+Then, both crates are moved from stack 2 to stack 1. Again, because crates are moved one at a time, crate C ends up below crate M:
+
+ [Z]
+ [N]
+[M] [D]
+[C] [P]
+ 1 2 3
+Finally, one crate is moved from stack 1 to stack 2:
+
+ [Z]
+ [N]
+ [D]
+[C] [M] [P]
+ 1 2 3
+The Elves just need to know which crate will end up on top of each stack; in this example, the top crates are C in stack 1, M in stack 2, and Z in stack 3, so you should combine these together and give the Elves the message CMZ.
+
+After the rearrangement procedure completes, what crate ends up on top of each stack?
+
+--- Part Two ---
+As you watch the crane operator expertly rearrange the crates, you notice the process isn't following your prediction.
+
+Some mud was covering the writing on the side of the crane, and you quickly wipe it away. The crane isn't a CrateMover 9000 - it's a CrateMover 9001.
+
+The CrateMover 9001 is notable for many new and exciting features: air conditioning, leather seats, an extra cup holder, and the ability to pick up and move multiple crates at once.
+
+Again considering the example above, the crates begin in the same configuration:
+
+ [D]
+[N] [C]
+[Z] [M] [P]
+ 1 2 3
+Moving a single crate from stack 2 to stack 1 behaves the same as before:
+
+[D]
+[N] [C]
+[Z] [M] [P]
+ 1 2 3
+However, the action of moving three crates from stack 1 to stack 3 means that those three moved crates stay in the same order, resulting in this new configuration:
+
+ [D]
+ [N]
+ [C] [Z]
+ [M] [P]
+ 1 2 3
+Next, as both crates are moved from stack 2 to stack 1, they retain their order as well:
+
+ [D]
+ [N]
+[C] [Z]
+[M] [P]
+ 1 2 3
+Finally, a single crate is still moved from stack 1 to stack 2, but now it's crate C that gets moved:
+
+ [D]
+ [N]
+ [Z]
+[M] [C] [P]
+ 1 2 3
+In this example, the CrateMover 9001 has put the crates in a totally different order: MCD.
+
+Before the rearrangement process finishes, update your simulation so that the Elves know where they should stand to be ready to unload the final supplies. After the rearrangement procedure completes, what crate ends up on top of each stack?
diff --git a/src/2022/day5/aoc.cpp b/src/2022/day5/aoc.cpp
index bfaaaf4..78eff91 100644
--- a/src/2022/day5/aoc.cpp
+++ b/src/2022/day5/aoc.cpp
@@ -3,8 +3,25 @@
#include <vector>
namespace aoc2022 {
-std::pair<int, int> day5(line_view file) {
- return {0,0};
+crate* crate::cs[9];
+void day5(line_view file, char* msg, int mode) {
+ crate::init();
+ per_line(file, [mode](line_view lv){
+ char c = *lv.line;
+ if (c == '[') {
+ const char* p = lv.line;
+ for(int i = 0; i < 9; i++) {
+ crate* c = crate::make(line_view{p, 4});
+ crate::add(c, i);
+ p += 4;
+ }
+ }
+ if (c == 'm') {
+ crate::move(lv, mode);
+ }
+ return true;
+ });
+ crate::message(msg);
}
diff --git a/src/2022/day5/aoc.h b/src/2022/day5/aoc.h
index 4b0d9d1..be1791e 100644
--- a/src/2022/day5/aoc.h
+++ b/src/2022/day5/aoc.h
@@ -1,8 +1,120 @@
#include "common.h"
-
+#include <vector>
namespace aoc2022 {
-std::pair<int, int> day5(line_view file);
+struct crate {
+ static crate* cs[9];
+
+ char value;
+ crate* prev = nullptr;
+ crate* next = nullptr;
+
+ static void init() {
+ for (int i = 0; i < 9; i++) {
+ cs[i] = new crate;
+ cs[i]->value = 0;
+ cs[i]->prev = cs[i];
+ cs[i]->next = cs[i];
+ }
+ }
+
+ static crate* make(line_view lv) {
+ crate* c = new crate;
+ c->value = *(lv.line + 1);
+ return c;
+ }
+
+ static crate* take(int i) {
+ crate* c = cs[i]->next;
+ c->next->prev = cs[i];
+ cs[i]->next = c->next;
+ return c;
+ }
+
+ static void print(int i) {
+ printf("%d: \"",i);
+
+ crate* c = cs[i]->prev;
+ while (c != cs[i]) {
+ printf("%c", c->value);
+ c = c->prev;
+ }
+ printf("\"");
+
+ // c = cs[i]->next;
+ // while (c != cs[i]) {
+ // printf("%c", c->value);
+ // c = c->next;
+ // }
+ printf("\n");
+ }
+
+ static void add(crate* c, int i) {
+ if (c->value >= 'A' && c->value <= 'Z') {
+ cs[i]->prev->next = c;
+ c->prev = cs[i]->prev;
+ c->next = cs[i];
+ cs[i]->prev = c;
+ // printf("add %c on %d\n", c->value, i);
+ }
+ }
+
+ static void put(crate* c, int i) {
+ if (c->value >= 'A' && c->value <= 'Z') {
+ cs[i]->next->prev = c;
+ c->next = cs[i]->next;
+ c->prev = cs[i];
+ cs[i]->next = c;
+ }
+ }
+
+ static void message(char *m) {
+ for (int i = 0; i < 9; i++) {
+ *m = cs[i]->next->value;
+ m++;
+ }
+ }
+
+ static void move(line_view lv, int mode) {
+ int d[3] = {0};
+ int* p = d;
+ const char *p0 = lv.line + 5;
+ while (p0 < lv.line + lv.length) {
+ if (*p0 >= '0' && *p0 <= '9') {
+ *p = *p * 10 + *p0 - '0';
+ }
+ else {
+ char c = *(p0 - 1);
+ if (c >= '0' && c <= '9') {
+ p++;
+ }
+ }
+ p0++;
+ }
+
+ d[1] -= 1;
+ d[2] -= 1;
+
+ if (mode == 1) {
+ while (d[0]-- > 0) {
+ crate* c = take(d[1]);
+ put(c, d[2]);
+ }
+ }
+ if (mode == 2) {
+ std::vector<crate*> dx;
+ for (int x = 0; x < d[0]; x++) {
+ crate* c = take(d[1]);
+ dx.push_back(c);
+ }
+ for (auto s = dx.size(); s > 0; s--) {
+ put(dx[s - 1], d[2]);
+ }
+ }
+ }
+};
+
+void day5(line_view file, char* msg, int mode);
}
diff --git a/src/2022/day5/input b/src/2022/day5/input
index e69de29..cbdf94c 100644
--- a/src/2022/day5/input
+++ b/src/2022/day5/input
@@ -0,0 +1,511 @@
+[ ] [W] [ ] [ ] [J] [ ] [J] [ ] [ ]
+[ ] [V] [ ] [F] [F] [S] [S] [ ] [ ]
+[ ] [S] [M] [R] [W] [M] [C] [ ] [ ]
+[ ] [M] [G] [W] [S] [F] [G] [ ] [C]
+[W] [P] [S] [M] [H] [N] [F] [ ] [L]
+[R] [H] [T] [D] [L] [D] [D] [B] [W]
+[T] [C] [L] [H] [Q] [J] [B] [T] [N]
+[G] [G] [C] [J] [P] [P] [Z] [R] [H]
+1 2 3 4 5 6 7 8 9
+
+move 3 from 4 to 3
+move 3 from 8 to 6
+move 2 from 3 to 8
+move 3 from 7 to 2
+move 1 from 1 to 3
+move 6 from 2 to 7
+move 5 from 3 to 6
+move 1 from 8 to 6
+move 4 from 4 to 3
+move 2 from 1 to 2
+move 10 from 7 to 3
+move 1 from 7 to 2
+move 6 from 5 to 8
+move 1 from 1 to 4
+move 7 from 6 to 3
+move 22 from 3 to 4
+move 3 from 2 to 8
+move 4 from 6 to 8
+move 5 from 2 to 1
+move 3 from 9 to 4
+move 2 from 4 to 3
+move 1 from 9 to 2
+move 1 from 5 to 3
+move 1 from 2 to 6
+move 1 from 5 to 2
+move 1 from 2 to 7
+move 4 from 4 to 5
+move 2 from 1 to 9
+move 1 from 1 to 3
+move 2 from 5 to 9
+move 5 from 9 to 8
+move 1 from 5 to 9
+move 1 from 7 to 2
+move 1 from 9 to 4
+move 5 from 6 to 7
+move 1 from 5 to 2
+move 2 from 2 to 4
+move 2 from 7 to 4
+move 2 from 7 to 8
+move 21 from 8 to 6
+move 6 from 3 to 1
+move 1 from 7 to 9
+move 1 from 1 to 7
+move 7 from 6 to 8
+move 3 from 1 to 9
+move 24 from 4 to 8
+move 3 from 1 to 3
+move 10 from 6 to 8
+move 1 from 4 to 5
+move 1 from 3 to 9
+move 5 from 9 to 8
+move 11 from 8 to 3
+move 1 from 5 to 7
+move 1 from 1 to 8
+move 1 from 6 to 1
+move 19 from 8 to 1
+move 1 from 7 to 9
+move 10 from 3 to 1
+move 3 from 3 to 8
+move 1 from 7 to 3
+move 1 from 9 to 2
+move 23 from 1 to 7
+move 1 from 1 to 9
+move 1 from 3 to 6
+move 2 from 6 to 9
+move 7 from 8 to 1
+move 8 from 8 to 1
+move 11 from 7 to 2
+move 2 from 6 to 8
+move 1 from 6 to 8
+move 7 from 8 to 6
+move 1 from 9 to 4
+move 1 from 8 to 1
+move 10 from 7 to 1
+move 6 from 2 to 5
+move 5 from 2 to 9
+move 4 from 5 to 8
+move 1 from 5 to 8
+move 13 from 1 to 6
+move 1 from 2 to 4
+move 1 from 4 to 5
+move 2 from 9 to 4
+move 3 from 9 to 4
+move 2 from 5 to 3
+move 1 from 3 to 9
+move 2 from 8 to 5
+move 2 from 5 to 7
+move 2 from 8 to 6
+move 2 from 7 to 3
+move 2 from 7 to 8
+move 4 from 1 to 3
+move 3 from 8 to 4
+move 8 from 4 to 9
+move 1 from 9 to 8
+move 3 from 3 to 6
+move 4 from 3 to 9
+move 1 from 8 to 2
+move 12 from 1 to 5
+move 9 from 6 to 8
+move 1 from 4 to 8
+move 3 from 1 to 3
+move 12 from 5 to 8
+move 1 from 2 to 6
+move 1 from 3 to 1
+move 1 from 3 to 2
+move 1 from 1 to 2
+move 16 from 6 to 1
+move 1 from 6 to 3
+move 2 from 3 to 8
+move 7 from 8 to 5
+move 1 from 2 to 6
+move 1 from 2 to 1
+move 2 from 9 to 4
+move 1 from 6 to 7
+move 8 from 9 to 8
+move 5 from 5 to 6
+move 9 from 8 to 7
+move 12 from 1 to 3
+move 2 from 6 to 3
+move 6 from 8 to 9
+move 5 from 1 to 4
+move 2 from 5 to 7
+move 11 from 7 to 3
+move 1 from 7 to 4
+move 2 from 6 to 8
+move 7 from 4 to 6
+move 3 from 8 to 7
+move 3 from 8 to 2
+move 19 from 3 to 2
+move 4 from 8 to 7
+move 2 from 9 to 8
+move 1 from 4 to 5
+move 1 from 6 to 8
+move 1 from 5 to 7
+move 8 from 9 to 4
+move 1 from 8 to 5
+move 1 from 5 to 6
+move 4 from 2 to 7
+move 8 from 6 to 9
+move 6 from 7 to 3
+move 4 from 3 to 8
+move 5 from 8 to 7
+move 15 from 2 to 8
+move 8 from 3 to 4
+move 7 from 9 to 7
+move 3 from 2 to 4
+move 2 from 7 to 4
+move 2 from 4 to 3
+move 1 from 9 to 4
+move 9 from 7 to 5
+move 4 from 5 to 9
+move 2 from 5 to 3
+move 2 from 9 to 1
+move 3 from 5 to 2
+move 4 from 3 to 1
+move 7 from 7 to 4
+move 3 from 2 to 6
+move 4 from 4 to 5
+move 2 from 1 to 6
+move 8 from 4 to 1
+move 1 from 8 to 2
+move 1 from 2 to 8
+move 11 from 8 to 7
+move 3 from 5 to 9
+move 1 from 5 to 9
+move 11 from 7 to 1
+move 7 from 8 to 9
+move 11 from 1 to 3
+move 6 from 4 to 5
+move 8 from 1 to 7
+move 4 from 6 to 5
+move 3 from 5 to 8
+move 8 from 7 to 3
+move 7 from 4 to 7
+move 7 from 5 to 6
+move 3 from 3 to 8
+move 2 from 4 to 9
+move 16 from 3 to 1
+move 7 from 7 to 1
+move 2 from 8 to 7
+move 2 from 8 to 1
+move 1 from 8 to 4
+move 1 from 7 to 4
+move 2 from 4 to 2
+move 1 from 8 to 7
+move 1 from 2 to 3
+move 1 from 2 to 4
+move 1 from 7 to 8
+move 8 from 6 to 7
+move 1 from 3 to 5
+move 15 from 1 to 2
+move 4 from 9 to 1
+move 1 from 8 to 1
+move 11 from 9 to 2
+move 21 from 2 to 6
+move 1 from 4 to 2
+move 4 from 2 to 7
+move 1 from 5 to 9
+move 1 from 9 to 4
+move 19 from 1 to 2
+move 5 from 2 to 4
+move 8 from 7 to 6
+move 10 from 6 to 2
+move 5 from 7 to 5
+move 2 from 4 to 1
+move 3 from 6 to 9
+move 3 from 9 to 2
+move 1 from 5 to 2
+move 13 from 6 to 3
+move 2 from 6 to 9
+move 17 from 2 to 3
+move 1 from 6 to 2
+move 2 from 2 to 1
+move 2 from 1 to 5
+move 5 from 5 to 3
+move 2 from 2 to 8
+move 10 from 2 to 1
+move 18 from 3 to 8
+move 13 from 8 to 1
+move 7 from 8 to 2
+move 2 from 2 to 1
+move 4 from 3 to 8
+move 1 from 2 to 7
+move 1 from 2 to 8
+move 2 from 4 to 1
+move 1 from 5 to 4
+move 1 from 9 to 6
+move 1 from 1 to 7
+move 11 from 3 to 4
+move 1 from 6 to 2
+move 7 from 1 to 2
+move 5 from 8 to 5
+move 1 from 7 to 5
+move 3 from 5 to 1
+move 7 from 1 to 6
+move 6 from 1 to 6
+move 6 from 1 to 8
+move 2 from 1 to 3
+move 5 from 2 to 5
+move 1 from 7 to 6
+move 1 from 4 to 2
+move 4 from 2 to 4
+move 1 from 1 to 9
+move 1 from 3 to 8
+move 7 from 8 to 5
+move 1 from 9 to 7
+move 1 from 9 to 4
+move 8 from 5 to 7
+move 5 from 4 to 1
+move 4 from 1 to 6
+move 3 from 1 to 6
+move 3 from 3 to 6
+move 1 from 5 to 6
+move 3 from 7 to 5
+move 15 from 6 to 7
+move 12 from 7 to 4
+move 8 from 5 to 2
+move 3 from 4 to 9
+move 3 from 9 to 7
+move 1 from 6 to 2
+move 9 from 4 to 9
+move 4 from 9 to 1
+move 2 from 1 to 7
+move 3 from 6 to 4
+move 3 from 6 to 4
+move 2 from 1 to 2
+move 1 from 5 to 6
+move 2 from 9 to 4
+move 13 from 4 to 2
+move 22 from 2 to 3
+move 3 from 7 to 8
+move 1 from 9 to 6
+move 1 from 9 to 3
+move 2 from 8 to 9
+move 3 from 9 to 8
+move 5 from 6 to 4
+move 2 from 8 to 6
+move 4 from 7 to 8
+move 2 from 2 to 5
+move 4 from 8 to 7
+move 2 from 5 to 7
+move 7 from 7 to 2
+move 9 from 4 to 7
+move 4 from 2 to 1
+move 3 from 7 to 6
+move 12 from 3 to 5
+move 5 from 2 to 5
+move 1 from 8 to 2
+move 1 from 3 to 5
+move 4 from 3 to 1
+move 2 from 6 to 1
+move 11 from 5 to 3
+move 3 from 6 to 1
+move 8 from 1 to 9
+move 5 from 9 to 8
+move 2 from 9 to 7
+move 1 from 1 to 8
+move 4 from 7 to 6
+move 6 from 3 to 1
+move 1 from 9 to 7
+move 5 from 7 to 4
+move 3 from 8 to 3
+move 1 from 6 to 5
+move 2 from 2 to 1
+move 4 from 7 to 9
+move 3 from 8 to 6
+move 6 from 3 to 8
+move 6 from 8 to 7
+move 4 from 6 to 5
+move 6 from 5 to 8
+move 2 from 9 to 5
+move 2 from 9 to 8
+move 4 from 7 to 4
+move 1 from 6 to 3
+move 5 from 8 to 4
+move 1 from 6 to 9
+move 1 from 7 to 3
+move 7 from 3 to 8
+move 6 from 1 to 4
+move 6 from 1 to 2
+move 17 from 4 to 6
+move 4 from 8 to 5
+move 3 from 3 to 1
+move 5 from 4 to 1
+move 5 from 2 to 7
+move 7 from 8 to 1
+move 7 from 7 to 2
+move 4 from 6 to 3
+move 6 from 1 to 8
+move 2 from 4 to 9
+move 2 from 5 to 4
+move 1 from 4 to 3
+move 1 from 4 to 7
+move 2 from 7 to 5
+move 4 from 5 to 3
+move 1 from 9 to 1
+move 5 from 5 to 3
+move 1 from 8 to 5
+move 7 from 6 to 1
+move 6 from 6 to 8
+move 11 from 3 to 7
+move 2 from 9 to 1
+move 8 from 8 to 2
+move 5 from 7 to 5
+move 5 from 7 to 4
+move 1 from 2 to 6
+move 2 from 4 to 6
+move 1 from 7 to 5
+move 2 from 6 to 4
+move 10 from 2 to 6
+move 3 from 4 to 5
+move 1 from 6 to 4
+move 4 from 6 to 4
+move 6 from 6 to 9
+move 3 from 3 to 8
+move 19 from 1 to 8
+move 23 from 8 to 9
+move 1 from 8 to 1
+move 1 from 1 to 7
+move 1 from 7 to 1
+move 1 from 1 to 6
+move 5 from 9 to 5
+move 1 from 8 to 5
+move 5 from 4 to 5
+move 4 from 5 to 4
+move 1 from 9 to 1
+move 6 from 9 to 3
+move 2 from 2 to 8
+move 1 from 1 to 3
+move 1 from 6 to 7
+move 1 from 7 to 3
+move 1 from 2 to 5
+move 6 from 9 to 8
+move 5 from 4 to 5
+move 10 from 5 to 2
+move 10 from 5 to 2
+move 11 from 9 to 1
+move 4 from 2 to 6
+move 18 from 2 to 9
+move 2 from 6 to 9
+move 3 from 3 to 9
+move 1 from 4 to 3
+move 1 from 6 to 8
+move 6 from 8 to 4
+move 6 from 5 to 7
+move 19 from 9 to 4
+move 7 from 1 to 3
+move 1 from 6 to 8
+move 4 from 8 to 7
+move 2 from 3 to 6
+move 3 from 1 to 8
+move 1 from 1 to 5
+move 7 from 7 to 3
+move 8 from 3 to 1
+move 1 from 5 to 7
+move 2 from 6 to 2
+move 3 from 1 to 8
+move 1 from 2 to 6
+move 3 from 1 to 7
+move 4 from 8 to 9
+move 4 from 7 to 6
+move 3 from 9 to 7
+move 3 from 9 to 3
+move 6 from 7 to 3
+move 13 from 3 to 1
+move 5 from 3 to 4
+move 1 from 8 to 7
+move 1 from 7 to 9
+move 1 from 8 to 5
+move 1 from 9 to 4
+move 1 from 5 to 2
+move 2 from 9 to 2
+move 3 from 6 to 2
+move 1 from 3 to 7
+move 13 from 4 to 8
+move 14 from 1 to 5
+move 6 from 2 to 7
+move 4 from 8 to 7
+move 1 from 1 to 3
+move 1 from 2 to 6
+move 5 from 4 to 2
+move 4 from 8 to 4
+move 12 from 5 to 4
+move 1 from 3 to 8
+move 9 from 4 to 2
+move 9 from 4 to 5
+move 1 from 4 to 5
+move 6 from 4 to 3
+move 5 from 8 to 4
+move 9 from 4 to 7
+move 4 from 2 to 3
+move 8 from 7 to 1
+move 2 from 7 to 1
+move 2 from 2 to 9
+move 1 from 6 to 7
+move 2 from 6 to 3
+move 1 from 2 to 3
+move 2 from 7 to 3
+move 3 from 3 to 7
+move 8 from 1 to 2
+move 9 from 5 to 3
+move 15 from 2 to 7
+move 20 from 7 to 5
+move 23 from 5 to 6
+move 20 from 6 to 8
+move 1 from 6 to 4
+move 2 from 9 to 7
+move 1 from 4 to 6
+move 3 from 7 to 6
+move 2 from 7 to 5
+move 13 from 3 to 5
+move 3 from 7 to 1
+move 13 from 5 to 4
+move 3 from 1 to 4
+move 5 from 6 to 1
+move 6 from 4 to 3
+move 1 from 7 to 4
+move 11 from 8 to 6
+move 1 from 8 to 6
+move 2 from 1 to 5
+move 2 from 5 to 3
+move 11 from 6 to 5
+move 3 from 8 to 3
+move 4 from 3 to 5
+move 15 from 5 to 1
+move 1 from 3 to 5
+move 3 from 8 to 5
+move 1 from 5 to 9
+move 1 from 5 to 3
+move 9 from 4 to 6
+move 7 from 6 to 8
+move 2 from 4 to 6
+move 2 from 5 to 1
+move 8 from 8 to 7
+move 6 from 6 to 2
+move 1 from 5 to 2
+move 4 from 3 to 4
+move 6 from 1 to 5
+move 7 from 3 to 4
+move 2 from 3 to 2
+move 2 from 8 to 9
+move 9 from 2 to 5
+move 9 from 5 to 4
+move 2 from 3 to 6
+move 14 from 1 to 7
+move 15 from 7 to 2
+move 1 from 1 to 7
+move 7 from 5 to 1
+move 2 from 9 to 2
+move 2 from 1 to 7
+move 1 from 1 to 4
+move 2 from 6 to 8
+move 7 from 2 to 8
+move 1 from 9 to 6
+move 7 from 8 to 3
+move 1 from 6 to 4
+move 1 from 8 to 2
+move 6 from 4 to 6
+move 9 from 2 to 1
+move 1 from 3 to 9
+move 3 from 7 to 5
diff --git a/test/test_2020.cpp b/test/test_2020.cpp
index 67ee4c9..3712327 100644
--- a/test/test_2020.cpp
+++ b/test/test_2020.cpp
@@ -65,3 +65,10 @@ TEST_CASE("Handheld Halting", "[2020]") {
REQUIRE(1814 == p.first);
REQUIRE(1056 == p.second);
}
+
+TEST_CASE("Encoding Error", "[2020]") {
+ line_view lv = load_file("../src/2020/day9/input");
+ auto p = aoc2020::day9(lv);
+ REQUIRE(22477624 == p.first);
+ // REQUIRE(0 == p.second);
+}
diff --git a/test/test_2022.cpp b/test/test_2022.cpp
index 3dfa704..387c575 100644
--- a/test/test_2022.cpp
+++ b/test/test_2022.cpp
@@ -5,6 +5,7 @@
#include "2022/day5/aoc.h"
#include "catch.hpp"
#include <stdio.h>
+#include <string.h>
TEST_CASE("Calorie Counting", "[2022]") {
line_view lv = load_file("../src/2022/day1/input");
@@ -36,7 +37,9 @@ TEST_CASE("Camp Cleanup", "[2022]") {
TEST_CASE("", "[2022]") {
line_view lv = load_file("../src/2022/day5/input");
- auto p = aoc2022::day5(lv);
- REQUIRE(0 == p.first);
- REQUIRE(0 == p.second);
+ char message[10] = {0};
+ aoc2022::day5(lv, message, 1);
+ REQUIRE(strcmp(message,"JCMHLVGMG") == 0);
+ aoc2022::day5(lv, message, 2);
+ REQUIRE(strcmp(message,"LVMRWSSPZ") == 0);
}