Update 24.cpp
This commit is contained in:
parent
346283bc8a
commit
ce8a6a1c79
13
2019/24.cpp
13
2019/24.cpp
@ -112,7 +112,7 @@ auto Neighbor2(std::pair<Coord, std::int64_t> cd) {
|
||||
}
|
||||
|
||||
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;
|
||||
for (auto const& x : bugs) {
|
||||
@ -132,7 +132,7 @@ auto Step(std::set<C> const& bugs, F const& neighbors)
|
||||
return result;
|
||||
}
|
||||
|
||||
auto Bio(std::set<Coord> const& bugs) {
|
||||
auto Bio(std::set<Coord> const& bugs) -> std::uint32_t {
|
||||
std::uint32_t result = 0;
|
||||
for (auto const& c : bugs) {
|
||||
result |= 1U << (5 * c.y + c.x);
|
||||
@ -140,15 +140,14 @@ auto Bio(std::set<Coord> const& bugs) {
|
||||
return result;
|
||||
}
|
||||
|
||||
auto Part1(std::set<Coord> const& bugs) {
|
||||
std::int64_t n = 0;
|
||||
auto Part1(std::set<Coord> const& bugs) -> std::uint32_t {
|
||||
auto cursor = bugs;
|
||||
std::set<std::uint32_t> seen;
|
||||
while (seen.insert(Bio(cursor)).second) {
|
||||
n++;
|
||||
std::uint32_t bio;
|
||||
while (seen.insert(bio = Bio(cursor)).second) {
|
||||
cursor = Step(cursor, Neighbor1);
|
||||
}
|
||||
return Bio(cursor);
|
||||
return bio;
|
||||
}
|
||||
|
||||
auto Part2(std::set<Coord> const& bugs) {
|
||||
|
Loading…
Reference in New Issue
Block a user