diff options
author | kaiwu <kaiwu2004@gmail.com> | 2022-04-16 14:16:51 +0800 |
---|---|---|
committer | kaiwu <kaiwu2004@gmail.com> | 2022-04-16 14:16:51 +0800 |
commit | 51f1930d6ba21e8760d65bc51881fed7c943c983 (patch) | |
tree | ee5db06751d42c7bffa393775ca67575234b266f /src/2018/day6/aoc.cpp | |
parent | 04e50217ffb0288e501c1f150a13b6ca70f1367a (diff) | |
download | advent-of-code-51f1930d6ba21e8760d65bc51881fed7c943c983.tar.gz advent-of-code-51f1930d6ba21e8760d65bc51881fed7c943c983.zip |
rows cols are confusing
Diffstat (limited to 'src/2018/day6/aoc.cpp')
-rw-r--r-- | src/2018/day6/aoc.cpp | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/src/2018/day6/aoc.cpp b/src/2018/day6/aoc.cpp index 745a185..df42be0 100644 --- a/src/2018/day6/aoc.cpp +++ b/src/2018/day6/aoc.cpp @@ -18,12 +18,12 @@ int day6(line_view file) { std::sort(cs.begin(), cs.end()); space_board b{maxx + 1, maxy + 1}; - printf("%d\n", b.size()); + //printf("%d %d\n", b.width, b.height); for (size_t i = 0; i < cs.size(); i++) { coordinate& c = cs[i]; - auto& p = b.ps[c.y * b.rows + c.x]; + auto& p = b.ps[c.y * b.width + c.x]; p.id = i; p.distance = 0; @@ -32,11 +32,10 @@ int day6(line_view file) { 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]; + if (x.x >= 0 && x.x < b.width && x.y >= 0 && x.y < b.height) { + auto& p = b.ps[x.y * b.width + x.x]; int d = x.distance(c); if (d == p.distance) { p.id = -2; // same distance @@ -56,15 +55,13 @@ int day6(line_view file) { return total[last] == 0; }; c.traverse(f, g); - printf("%zu %d\n", i, win); + // b.print(); + // 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) { |