Update 24.cpp

This commit is contained in:
Eric Mertens 2022-11-11 15:10:56 -08:00
parent 346283bc8a
commit ce8a6a1c79

View File

@ -112,7 +112,7 @@ auto Neighbor2(std::pair<Coord, std::int64_t> cd) {
} }
template<class F, class C> template<class F, class C>
auto Step(std::set<C> const& bugs, F const& neighbors) auto Step(std::set<C> const& bugs, F neighbors)
{ {
std::map<C, int> adjacent; std::map<C, int> adjacent;
for (auto const& x : bugs) { for (auto const& x : bugs) {
@ -132,7 +132,7 @@ auto Step(std::set<C> const& bugs, F const& neighbors)
return result; return result;
} }
auto Bio(std::set<Coord> const& bugs) { auto Bio(std::set<Coord> const& bugs) -> std::uint32_t {
std::uint32_t result = 0; std::uint32_t result = 0;
for (auto const& c : bugs) { for (auto const& c : bugs) {
result |= 1U << (5 * c.y + c.x); result |= 1U << (5 * c.y + c.x);
@ -140,15 +140,14 @@ auto Bio(std::set<Coord> const& bugs) {
return result; return result;
} }
auto Part1(std::set<Coord> const& bugs) { auto Part1(std::set<Coord> const& bugs) -> std::uint32_t {
std::int64_t n = 0;
auto cursor = bugs; auto cursor = bugs;
std::set<std::uint32_t> seen; std::set<std::uint32_t> seen;
while (seen.insert(Bio(cursor)).second) { std::uint32_t bio;
n++; while (seen.insert(bio = Bio(cursor)).second) {
cursor = Step(cursor, Neighbor1); cursor = Step(cursor, Neighbor1);
} }
return Bio(cursor); return bio;
} }
auto Part2(std::set<Coord> const& bugs) { auto Part2(std::set<Coord> const& bugs) {