aboutsummaryrefslogtreecommitdiff
path: root/src/2017/day24/aoc.h
blob: 9643b7846e356a81463ee85656cf627ed89e80a6 (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
#pragma once
#include "common.h"
#include <vector>

namespace aoc2017 {

struct component {
  int pins[2] = {0};

  void get_number(const char** pp, int* d) {
    const char* p = *pp;
    while (*p >= '0' && *p <= '9') {
      *d = *d * 10 + *p - '0';
      p++;
    }
    *pp = p;
  }

  void print() const noexcept { printf("%d/%d\n", pins[0], pins[1]); }

  component(line_view lv) {
    int i{0};
    const char* p = lv.line;
    while (p < lv.line + lv.length) {
      if (*p >= '0' && *p <= '9') {
        get_number(&p, &pins[i++]);
      }
      p++;
    }
  }
};

std::pair<int64_t, int64_t> day24(line_view);
} // namespace aoc2017