aboutsummaryrefslogtreecommitdiff
path: root/src/2017/day10/aoc.cpp
blob: 1e8461e55dfbaac7390aeb673913c3f3a26e2d29 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#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<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(&current, d);
    p++;
  }

  print(current);
  return {0, 0};
}
} // namespace aoc2017