blob: ba0d5bce8daca53886155dcb6614f2bc2a431ff5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
#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<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
|