diff options
Diffstat (limited to 'src/2017/day17/aoc.cpp')
-rw-r--r-- | src/2017/day17/aoc.cpp | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/src/2017/day17/aoc.cpp b/src/2017/day17/aoc.cpp index f2a9d5a..ba0d5bc 100644 --- a/src/2017/day17/aoc.cpp +++ b/src/2017/day17/aoc.cpp @@ -2,6 +2,40 @@ namespace aoc2017 { -std::pair<int64_t, int64_t> day17(line_view file) { return {0, 0}; } +static spinlock* next(spinlock* x, int step) { + while (step-- > 0) { + x = x->next; + } + return x; +} + +static void insert(spinlock* s, spinlock** current, int v) { + spinlock* n = s->next; + spinlock* x = new spinlock; + x->val = v; + s->next = x; + x->prev = s; + x->next = n; + n->prev = x; + *current = x; +} + +std::pair<int64_t, int64_t> day17(line_view file) { + spinlock* l = new spinlock; + l->val = 0; + l->next = l; + l->prev = l; + // spinlock* l0 = l; + + int step{356}; + for (int i = 1; i < 2018; i++) { + l = next(l, step); + insert(l, &l, i); + } + int t0 = l->next->val; + // printf("%d\n", l0->next->val); + + return {t0, 0}; +} } // namespace aoc2017 |