aboutsummaryrefslogtreecommitdiff
path: root/src/2017/day11/aoc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/2017/day11/aoc.cpp')
-rw-r--r--src/2017/day11/aoc.cpp51
1 files changed, 50 insertions, 1 deletions
diff --git a/src/2017/day11/aoc.cpp b/src/2017/day11/aoc.cpp
index f6b5864..9c6f780 100644
--- a/src/2017/day11/aoc.cpp
+++ b/src/2017/day11/aoc.cpp
@@ -2,5 +2,54 @@
namespace aoc2017 {
-std::pair<int64_t, int64_t> day11(line_view) { return {0, 0}; }
+void route(hd in, hd out, int* step) {
+ constexpr static int steps[6][6] = {
+ {1, 1, 1, 0, 0, -1},
+ {1, 1, 0, 1, -1, 0}, // ne
+ {1, 0, 1, -1, 1, 0}, // nw
+ {0, 1, -1, 1, 0, 1}, // se
+ {0, -1, 1, 0, 1, 1}, // sw
+ {-1, 0, 0, 1, 1, 1},
+ };
+
+ auto x = static_cast<int>(in);
+ auto y = static_cast<int>(out);
+ *step += steps[x][y];
+}
+
+hd inout(hd x) {
+ hd d6[] = {hd::s, hd::sw, hd::se, hd::nw, hd::ne, hd::n};
+ return d6[static_cast<int>(x)];
+}
+
+std::pair<int64_t, int64_t> day11(line_view file) {
+ std::vector<hd> ds;
+ const char* p0 = file.line;
+ const char* p1 = p0;
+ line_view d6[] = {"n", "ne", "nw", "se", "sw", "s"};
+ while (p1 < file.line + file.length) {
+ if (*p1 == ',' || *p1 == '\n') {
+ line_view d{p0, p1};
+ for (int i = 0; i < 6; i++) {
+ if (d6[i] == d) {
+ ds.push_back(static_cast<hd>(i));
+ break;
+ }
+ }
+ p0 = p1 + 1;
+ }
+ p1++;
+ }
+
+ int step{1};
+ for (size_t i = 0; i < ds.size() - 1; i++) {
+ auto j = i + 1;
+ hd in = inout(ds[i]);
+ hd out = ds[j];
+ route(in, out, &step);
+ }
+ printf("%d\n", step);
+ return {0, 0};
+}
+
} // namespace aoc2017