#include "aoc.h" namespace aoc2017 { 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 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