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

namespace aoc2016 {

struct maze {
  struct pos {
    int x;
    int y;

    friend bool operator<(pos p1, pos p2) { return p1.x < p2.x ? true : p1.x > p2.x ? false : p1.y < p2.y; }
    friend bool operator==(pos p1, pos p2) { return p1.x == p2.x && p1.y == p2.y; }
  };

  char* ps = nullptr;
  int width;
  int height;
  std::set<pos> numbers;

  char& get(int x, int y) { return *(ps + width * y + x); }

  void load(int r, line_view lv) {
    const char* p = lv.line;
    int x{0};
    while (p < lv.line + lv.length - 1) {
      get(x, r) = *p;
      if (*p >= '0' && *p <= '9') {
        numbers.insert({x, r});
      }
      x++;
      p++;
    }
  }

  void print() {
    for (int y = 0; y < height; y++) {
      for (int x = 0; x < width; x++) {
        printf("%c", get(x, y));
      }
      printf("\n");
    }
  }

  maze(int mx, int my) : width(mx), height(my) {
    ps = (char*)malloc(width * height);
    memset(ps, 0, width * height);
  }
};

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