#include "aoc.h" namespace aoc2017 { 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 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(¤t, d); p++; } print(current); return {0, 0}; } } // namespace aoc2017