Day8P2
This commit is contained in:
parent
9a3e228f00
commit
b359a6dd54
1 changed files with 23 additions and 7 deletions
|
|
@ -70,12 +70,12 @@ static auto getDistances(const std::vector<Point> &pointVec) -> auto {
|
|||
return sortedMap;
|
||||
}
|
||||
|
||||
static auto doTheThing(const std::vector<Point> &pointVec, int numberToTake) -> auto {
|
||||
static auto doTheThing(const std::vector<Point> &pointVec, int numberToTake) -> long long {
|
||||
auto distanceMap = getDistances(pointVec);
|
||||
std::map<Point, int> pointToCircuitMap{};
|
||||
std::unordered_map<int, std::vector<Point>> circuitMap;
|
||||
int currentCircuit = 0;
|
||||
for (const auto &[combination, distance] : distanceMap | std::views::take(numberToTake)) {
|
||||
for (const auto &[combination, distance] : distanceMap) {
|
||||
const auto &[left, right] = combination;
|
||||
// std::println("DistanceMap: {}:{} = {}", left, right, distance);
|
||||
|
||||
|
|
@ -84,13 +84,19 @@ static auto doTheThing(const std::vector<Point> &pointVec, int numberToTake) ->
|
|||
int rightCircuit = pointToCircuitMap[right];
|
||||
// std::println("Left circuit: {}. Right circuit: {}", leftCircuit, rightCircuit);
|
||||
if (leftCircuit != rightCircuit) {
|
||||
// std::println("Fuck: {} to {}", left, right);
|
||||
std::println("Merge: {} to {}", left, right);
|
||||
|
||||
for (const auto &rightCircuitPoint : circuitMap[rightCircuit]) {
|
||||
pointToCircuitMap[rightCircuitPoint] = leftCircuit;
|
||||
}
|
||||
circuitMap[leftCircuit].append_range(circuitMap[rightCircuit]);
|
||||
circuitMap.erase(rightCircuit);
|
||||
|
||||
// std::println("mergesize: {}", circuitMap[leftCircuit].size());
|
||||
if (circuitMap[leftCircuit].size() >= pointVec.size()) {
|
||||
|
||||
return (long long)std::get<0>(left) * (long long)std::get<0>(right);
|
||||
}
|
||||
}
|
||||
} else if (pointToCircuitMap.contains(left)) {
|
||||
int leftCircuit = pointToCircuitMap[left];
|
||||
|
|
@ -98,12 +104,22 @@ static auto doTheThing(const std::vector<Point> &pointVec, int numberToTake) ->
|
|||
pointToCircuitMap[right] = pointToCircuitMap[left];
|
||||
|
||||
circuitMap[leftCircuit].push_back(right);
|
||||
// std::println("leftsize: {}", circuitMap[leftCircuit].size());
|
||||
if (circuitMap[leftCircuit].size() >= pointVec.size()) {
|
||||
|
||||
return (long long)std::get<0>(left) * (long long)std::get<0>(right);
|
||||
}
|
||||
} else if (pointToCircuitMap.contains(right)) {
|
||||
int rightCircuit = pointToCircuitMap[right];
|
||||
// std::println("Only right exists: {} to {}", left, right);
|
||||
pointToCircuitMap[left] = pointToCircuitMap[right];
|
||||
|
||||
circuitMap[rightCircuit].push_back(left);
|
||||
// std::println("rightsize: {}", circuitMap[rightCircuit].size());
|
||||
if (circuitMap[rightCircuit].size() >= pointVec.size()) {
|
||||
|
||||
return (long long)std::get<0>(left) * (long long)std::get<0>(right);
|
||||
}
|
||||
} else {
|
||||
currentCircuit++;
|
||||
pointToCircuitMap[left] = currentCircuit;
|
||||
|
|
@ -145,11 +161,11 @@ auto main() -> int {
|
|||
|
||||
auto realPuzzle = parseInput("puzzle_input");
|
||||
if (realPuzzle) {
|
||||
auto realResult = doTheThing(*realPuzzle, 1000);
|
||||
std::println("P1 Real result: {}", realResult);
|
||||
// auto realResult = doTheThing(*realPuzzle, 1000);
|
||||
// std::println("P1 Real result: {}", realResult);
|
||||
|
||||
// auto realResultP2 = treePartTwo(*realPuzzle);
|
||||
// std::println("P1 Real result: {}", realResultP2);
|
||||
auto realResultP2 = doTheThing(*realPuzzle, 1000);
|
||||
std::println("P2 Real result: {}", realResultP2);
|
||||
} else {
|
||||
std::print("{}\n", realPuzzle.error());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue