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

namespace aoc2017 {

struct pos {
  int x;
  int y;
};

struct alpha_grid {
  int width;
  int height;
  char* grid;

  pos start;

  alpha_grid(int w, int h) : width(w), height(h) {
    grid = (char*)malloc(width * height);
    memset(grid, 0, width * height);
    start = {INT32_MAX, INT32_MAX};
  }

  char& get(int x, int y) {
    static char space = ' ';
    return x >= 0 && x < width && y >= 0 && y < height ? *(grid + y * width + x) : space;
  }

  char& get(pos p) { return get(p.x, p.y); }

  void load(int r, line_view lv) {
    const char* p = lv.line;
    for (int i = 0; i < width; i++) {
      get(i, r) = *(p + i);
      if (r == 0 && get(i, r) == '|') {
        start = {i, r};
      }
    }
  }
};

std::pair<std::string, int64_t> day19(line_view);

} // namespace aoc2017