advent2024

Advent of Code 2024
git clone git://bsandro.tech/advent2024
Log | Files | Refs

commit 4343c0b16e751b1ec4e02f3e2c45ccf6dafe4d77
parent 2731cabf57beb5d1331af00d10929971b631591d
Author: bsandro <email@bsandro.tech>
Date:   Thu, 26 Dec 2024 08:53:31 +0200

Day 12 p2 more sample data works yet real input does not

Diffstat:
Mday12/Makefile | 6++++++
Mday12/main.cpp | 14++++++--------
2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/day12/Makefile b/day12/Makefile @@ -35,3 +35,9 @@ test4: $(NAME) test5: $(NAME) @./$(NAME) test5.txt + +test6: $(NAME) + @./$(NAME) test6.txt + +test7: $(NAME) + @./$(NAME) test7.txt diff --git a/day12/main.cpp b/day12/main.cpp @@ -15,12 +15,10 @@ typedef std::pair<int, int> Vec2; static const std::vector<Vec2> sDirs = {Vec2(0, -1), Vec2(1, 0), Vec2(0, 1), Vec2(-1, 0)}; - class Plot : public std::set<Vec2> { public: bool has(const Vec2 &p) const { return this->count(p)>0; - //std::count(this->begin(), this->end(), p)>0; } bool addNeighbors(const Data &input, char c) { @@ -69,16 +67,16 @@ public: if (!this->has(Vec2(p.first, p.second+1))) s.push_back(p); if (!this->has(Vec2(p.first, p.second-1))) n.push_back(p); } - std::sort(n.begin(), n.end(), [](auto &p1, auto &p2){ return p1.second<p2.second/* && p1.first<p2.first*/; }); + std::sort(n.begin(), n.end(), [](auto &p1, auto &p2){ return p1.second<p2.second; }); std::sort(s.begin(), s.end(), [](auto &p1, auto &p2){ return p1.second<p2.second; }); std::sort(e.begin(), e.end(), [](auto &p1, auto &p2){ return p1.first<p2.first; }); std::sort(w.begin(), w.end(), [](auto &p1, auto &p2){ return p1.first<p2.first; }); - std::printf("east:"); + /*std::printf("east:"); for (auto &p:e) { std::printf("[%d,%d]", p.first, p.second); } - std::printf("\n"); + std::printf("\n");*/ int v=-1; int prev=-1; @@ -101,7 +99,7 @@ public: v=p.first; prev=p.second; } - std::printf("north+south+east count:%ld\n", cnt); + //std::printf("north+south+east count:%ld\n", cnt); v=-1; prev=-1; for (auto &p : w) { @@ -154,9 +152,9 @@ std::pair<int64_t, int64_t> solve(Data &input [[ maybe_unused ]]) { if (!processed.has(Vec2(x, y))) { Plot p = findPlot(input, Vec2(x,y)); processed.insert(p.begin(), p.end()); - std::printf("\n-------------\nfound plot (%c):\n", input[y][x]); + std::printf("-------------\nfound plot (%c):\n", input[y][x]); p.print(); - std::printf("\nsides: %ld\n", p.sides()); + std::printf("\nsides: %ld, area: %ld\n", p.sides(), p.area()); p1sum += p.area() * p.perimeter(); p2sum += p.area() * p.sides(); }