aboutsummaryrefslogtreecommitdiff
path: root/src/2022/day15/aoc.cpp
blob: 09a923f91ff888cd76f499706d85fd76feb02eed (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
#include "aoc.h"
#include <set>

namespace aoc2022 {
int sensor::minx;
int sensor::maxx;


int no_beacon(int y, std::vector<sensor>& ss) {
  int count{0};
  for (int x = sensor::minx; x <= sensor::maxx; x++) {
    sensor::pos p;
    p.x = x;
    p.y = y;
    size_t n{0};
    for (auto&s : ss) {
      if(s.inscope(p)) {
        n++;
      }
    }
    // printf("(%d, %d) has %zu\n", x, y, n);
    count += (bool) n > 0;
  }
  return count;
}

bool valid(sensor::pos p, int dx) {
  return p.x >= 0 && p.x <= dx && p.y >= 0 && p.y <= dx;
}

int only_beacon(int dx, std::vector<sensor>& ss) {
  return 0;
}

std::pair<int, int> day15(line_view file) {
  std::vector<sensor> ss;
  per_line(file, [&ss](line_view lv){
      ss.emplace_back(lv);
      return true;
  });
  int n1 = no_beacon(2000000, ss);
  int n2 = only_beacon(4000000, ss);
  return {n1, n2};
}
}