aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/2017/day10/aoc.cpp76
-rw-r--r--src/2017/day10/aoc.h8
-rw-r--r--src/2017/day10/input01
3 files changed, 84 insertions, 1 deletions
diff --git a/src/2017/day10/aoc.cpp b/src/2017/day10/aoc.cpp
index 9ba0d48..1e8461e 100644
--- a/src/2017/day10/aoc.cpp
+++ b/src/2017/day10/aoc.cpp
@@ -2,5 +2,79 @@
namespace aoc2017 {
-std::pair<int64_t, int64_t> day10(line_view) { return {0, 0}; }
+knot* make_knot(int n) {
+ knot* k = new knot;
+ k->val = 0;
+ k->next = k;
+ k->prev = k;
+ knot* last = k;
+ for (int i = 1; i < n; i++) {
+ knot* n = new knot;
+ n->val = i;
+ last->next = n;
+ n->prev = last;
+ last = n;
+ k->prev = last;
+ last->next = k;
+ }
+ return k;
+}
+
+static void print(knot* k) {
+ knot* n = k;
+ do {
+ printf("%d ", n->val);
+ n = n->next;
+ } while (n != k);
+ printf("\n");
+}
+
+void forward(knot** k, int n) {
+ knot* x = *k;
+ while (n-- > 0) {
+ x = x->next;
+ }
+ *k = x;
+}
+
+// static void reverse(knot* head, knot* tail) {
+// }
+
+static int get_number(const char** pp) {
+ int d{0};
+ const char* p = *pp;
+ while (*p >= '0' && *p <= '9') {
+ d = d * 10 + *p - '0';
+ p++;
+ }
+ *pp = p;
+ return d;
+}
+
+static void reverse(knot* head, int d) {}
+
+static void reverse_skip(knot** current, int d) {
+ static int skip = 0;
+
+ reverse(*current, d);
+ forward(current, d + skip);
+ skip += 1;
+}
+
+std::pair<int64_t, int64_t> day10(line_view file) {
+ knot* k = make_knot(256);
+
+ const char* p = file.line;
+ knot* current = k;
+ print(current);
+ while (p < file.line + file.length) {
+ int d = get_number(&p);
+ // printf("%d\n", d);
+ reverse_skip(&current, d);
+ p++;
+ }
+
+ print(current);
+ return {0, 0};
+}
} // namespace aoc2017
diff --git a/src/2017/day10/aoc.h b/src/2017/day10/aoc.h
index 9fea13e..a4cdca8 100644
--- a/src/2017/day10/aoc.h
+++ b/src/2017/day10/aoc.h
@@ -3,5 +3,13 @@
#include <vector>
namespace aoc2017 {
+
+struct knot {
+ int val;
+ knot* next = nullptr;
+ knot* prev = nullptr;
+};
+
+
std::pair<int64_t, int64_t> day10(line_view);
}
diff --git a/src/2017/day10/input0 b/src/2017/day10/input0
index e69de29..cf15122 100644
--- a/src/2017/day10/input0
+++ b/src/2017/day10/input0
@@ -0,0 +1 @@
+3,4,1,5