diff options
author | kaiwu <kaiwu2004@gmail.com> | 2023-02-06 23:02:18 +0800 |
---|---|---|
committer | kaiwu <kaiwu2004@gmail.com> | 2023-02-06 23:02:18 +0800 |
commit | f543b8886bf13d735cd4fe5fb5b16d43f719721e (patch) | |
tree | 1d74884950feb2b5ab39e7f8bd5aa8a8c7222175 | |
parent | 2e1e1c720e799eb6063bb8dd9d88d6b387506b4c (diff) | |
download | advent-of-code-f543b8886bf13d735cd4fe5fb5b16d43f719721e.tar.gz advent-of-code-f543b8886bf13d735cd4fe5fb5b16d43f719721e.zip |
2017 day10 part1
-rw-r--r-- | src/2017/day10/aoc.cpp | 76 | ||||
-rw-r--r-- | src/2017/day10/aoc.h | 8 | ||||
-rw-r--r-- | src/2017/day10/input0 | 1 |
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(¤t, 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 |