diff --git a/2024/day-05/main.cpp b/2024/day-05/main.cpp index 76f5ccf..49e6e18 100644 --- a/2024/day-05/main.cpp +++ b/2024/day-05/main.cpp @@ -36,13 +36,6 @@ vector> readManuals() return manuals; } -void sortRules(vector> &rules) -{ - sort(rules.begin(), rules.end(), [](const pair &a, const pair &b) { - return a.first < b.first; - }); -} - bool isCorrectPageOrdering(const int firstPage, const int secondPage, const vector> &rules) @@ -82,15 +75,23 @@ int main() sort(rules.begin(), rules.end()); int sumOfCorrectMiddlePages = 0; + int sumOfCorrectedMiddlePages = 0; for (const vector &pages : manuals) { const vector properlyOrderedPages = getProperlyOrderedPages(pages, rules); if (pages == properlyOrderedPages) { sumOfCorrectMiddlePages += getMiddlePageNumber(pages); + } else { + sumOfCorrectedMiddlePages += getMiddlePageNumber(properlyOrderedPages); } } // Part one cout << "Sum of the middle page numbers of all correctly ordered manuals: " << sumOfCorrectMiddlePages << endl; + + // Part two + cout + << "Sum of the middle page numbers of all incorrectly ordered manuals after ordering them: " + << sumOfCorrectedMiddlePages << endl; }