aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/2018/day6/aoc.cpp36
-rw-r--r--src/2018/day6/aoc.h12
-rw-r--r--src/2018/day6/input06
3 files changed, 37 insertions, 17 deletions
diff --git a/src/2018/day6/aoc.cpp b/src/2018/day6/aoc.cpp
index 07f8ad9..745a185 100644
--- a/src/2018/day6/aoc.cpp
+++ b/src/2018/day6/aoc.cpp
@@ -12,47 +12,59 @@ int day6(line_view file) {
coordinate c(lv);
cs.push_back(c);
maxx = std::max(maxx, c.x);
- maxy = std::max(maxx, c.y);
+ maxy = std::max(maxy, c.y);
return true;
});
std::sort(cs.begin(), cs.end());
space_board b{maxx + 1, maxy + 1};
+ printf("%d\n", b.size());
for (size_t i = 0; i < cs.size(); i++) {
coordinate& c = cs[i];
+
auto& p = b.ps[c.y * b.rows + c.x];
p.id = i;
p.distance = 0;
- std::vector<int> total = {0};
+ std::vector<int> total(1, 0);
+ int win{1};
- auto f = [&total, &b, &c, &i](size_t lap, coordinate x) {
- if (x.x >= 0 && x.x <= b.cols && x.y >= 0 && x.y <= b.rows) {
- if (lap == total.size()) {
- total.push_back(0);
- }
+ auto f = [&win, &total, &b, &c, &i](size_t lap, coordinate x) {
+ if (lap == total.size()) {
+ // printf("%zu, %d %d\n", lap - 1, total[lap - 1], win);
+ total.push_back(0);
+ }
+ if (x.x >= 0 && x.x < b.cols && x.y >= 0 && x.y < b.rows) {
auto& p = b.ps[x.y * b.rows + x.x];
int d = x.distance(c);
+ if (d == p.distance) {
+ p.id = -2; // same distance
+ total[lap] += 1;
+ }
if (d < p.distance) {
p.id = i;
p.distance = d;
total[lap] += 1;
- }
- if (d == p.distance) {
- p.id = -2; // same distance
- total[lap] += 1;
+ win += 1;
}
}
return true;
};
- auto g = [&total]() { return total[total.size() - 1] == 0; };
+ auto g = [&total]() {
+ int last = total.size() - 1;
+ return total[last] == 0;
+ };
c.traverse(f, g);
+ printf("%zu %d\n", i, win);
}
std::vector<int> xs(cs.size(), 0);
b.count(xs);
+ std::for_each(xs.begin(), xs.end(), [](int d) { printf("%d ", d); });
+ printf("\n");
+
int max{INT32_MIN};
for (auto& x : xs) {
if (x != INT32_MAX && x > max) {
diff --git a/src/2018/day6/aoc.h b/src/2018/day6/aoc.h
index 9bb86d7..6e5b96f 100644
--- a/src/2018/day6/aoc.h
+++ b/src/2018/day6/aoc.h
@@ -83,11 +83,13 @@ struct space_board {
std::vector<point> ps;
space_board(int x, int y) : rows(y), cols(x), ps(x * y, {-1, INT32_MAX}){};
- void count(std::vector<int>& area) {
- for (int y = 0; y < cols; y++) {
- for (int x = 0; x < rows; x++) {
- auto p = ps[y * rows + x];
- if (x == 0 || y == 0 || x == rows - 1 || y == cols - 1) {
+ int size() const noexcept { return rows * cols; }
+
+ void count(std::vector<int>& area) const noexcept {
+ for (int y = 0; y < rows; y++) {
+ for (int x = 0; x < cols; x++) {
+ auto& p = ps[y * rows + x];
+ if (x == 0 || y == 0 || x == cols - 1 || y == rows - 1) {
area[p.id] = INT32_MAX;
}
if (area[p.id] < INT32_MAX) {
diff --git a/src/2018/day6/input0 b/src/2018/day6/input0
new file mode 100644
index 0000000..95d160a
--- /dev/null
+++ b/src/2018/day6/input0
@@ -0,0 +1,6 @@
+1, 1
+1, 6
+8, 3
+3, 4
+5, 5
+8, 9