aboutsummaryrefslogtreecommitdiff
path: root/src/2016/day10/aoc.h
blob: ea735292c8c279e153c08b72fef516078031be00 (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
#pragma once
#include "common.h"
#include <vector>

namespace aoc2016 {

struct bot {
  int idx;
  int vs[2] = {0, 0};
  std::vector<int> values;
  bot* outputs[2] = {nullptr, nullptr};
  bool is_output = false;

  bool can_give() const noexcept { return vs[0] != 0 && vs[1] != 0; }
  bool set(int v) {
    bool done{false};
    for (int i = 0; i < 2; i++) {
      if (vs[i] == 0) {
        done = true;
        vs[i] = v;
        break;
      }
    }
    if (vs[0] > vs[1]) {
      std::swap(vs[0], vs[1]);
    }
    return done;
  }

  void get(int v) { // bot as output
    values.push_back(v);
  }
};
std::pair<int64_t, int64_t> day10(line_view);
} // namespace aoc2016