diff --git a/Aufgabe 5/main.cpp b/Aufgabe 5/main.cpp index 3dd05eb..1d9f9a6 100644 --- a/Aufgabe 5/main.cpp +++ b/Aufgabe 5/main.cpp @@ -176,6 +176,42 @@ std::vector determineCorrectUpdates(std::vector& updates, std::v return validUpdates; } +std::vector determineIncorrectUpdates(std::vector& updates, std::vector& rules) { + std::vector validUpdates; + for(const Update& update : updates) { + if(!isUpdateCorrect(update, rules)) { + validUpdates.push_back(update); + } + } + return validUpdates; +} + +Update correctUpdate(const Update& update, std::vector& rules) { + Update correctedUpdate = update; + for(int i=0; i correctUpdates(std::vector& updates, std::vector& rules) { + std::vector correctedUpdates; + for(const Update& update : updates) { + correctedUpdates.push_back(correctUpdate(update, rules)); + } + return correctedUpdates; +} + int calcMiddleSum(std::vector& updates) { int sum = 0; for(const auto& update: updates) { @@ -188,8 +224,13 @@ int main() { std::vector input = readTextFromFile("../input.txt"); std::vector rules = parseRules(input); std::vector updates = parseUpdates(input); - std::vector correctUpdates = determineCorrectUpdates(updates, rules); - int result = calcMiddleSum(correctUpdates); + std::vector validUpdates = determineCorrectUpdates(updates, rules); + int result = calcMiddleSum(validUpdates); std::cout << "The middle sum of the correct Updates is: " << result << std::endl; + + std::vector incorrectUpdates = determineIncorrectUpdates(updates, rules); + std::vector correctedUpdates = correctUpdates(incorrectUpdates, rules); + int result2 = calcMiddleSum(correctedUpdates); + std::cout << "The middle sum of the corrected Updates is: " << result2 << std::endl; return 0; }