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
|
#include "common.h"
#include <vector>
namespace aoc2022 {
// which blueprint would maximize the number of opened geodes after 24 minutes
// by figuring out which robots to build and when to build them.
// geod <- obsi <- clay <- ore
// ore ore
struct blueprint {
int idx = 0;
int c_ore_r[2] = {0, 0}; // ore
int c_clay_r[2] = {0, 0}; // ore
int c_obsi_r[2] = {0, 0}; // ore + clay
int c_geod_r[2] = {0, 0}; // ore + obsidian
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 %d [%d,%d] [%d,%d]\n", idx, c_ore_r[0], c_clay_r[0], c_obsi_r[0], c_obsi_r[1], c_geod_r[0], c_geod_r[1]);
}
blueprint(line_view lv) {
const char* p = lv.line;
int i{0};
int* ps[7] = {&idx, c_ore_r, c_clay_r, c_obsi_r, c_obsi_r + 1, c_geod_r, c_geod_r + 1};
while (p < lv.line + lv.length) {
if (*p >= '0' && *p <= '9') {
get_number(&p, ps[i++]);
}
p++;
}
}
};
std::pair<int, int> day19(line_view);
} // namespace aoc2022
|