From 56d5f3fc54e84c318300bf012a91c1e7068a1698 Mon Sep 17 00:00:00 2001 From: Jose Caban <43381096+AssKoala@users.noreply.github.com> Date: Mon, 1 Dec 2025 16:48:35 -0500 Subject: [PATCH] Small refactor for solution class --- 2025/Cpp/AdventHelpers/AdventHelpers.vcxproj | 1 + .../AdventHelpers.vcxproj.filters | 3 ++ .../AdventHelpers/AdventOfCodeSolution.h | 38 +-------------- .../source/AdventOfCodeSolution.cpp | 47 +++++++++++++++++++ 4 files changed, 52 insertions(+), 37 deletions(-) create mode 100644 2025/Cpp/AdventHelpers/source/AdventOfCodeSolution.cpp diff --git a/2025/Cpp/AdventHelpers/AdventHelpers.vcxproj b/2025/Cpp/AdventHelpers/AdventHelpers.vcxproj index 54223e4..998e02a 100644 --- a/2025/Cpp/AdventHelpers/AdventHelpers.vcxproj +++ b/2025/Cpp/AdventHelpers/AdventHelpers.vcxproj @@ -155,6 +155,7 @@ + diff --git a/2025/Cpp/AdventHelpers/AdventHelpers.vcxproj.filters b/2025/Cpp/AdventHelpers/AdventHelpers.vcxproj.filters index 2372d6b..4999ec0 100644 --- a/2025/Cpp/AdventHelpers/AdventHelpers.vcxproj.filters +++ b/2025/Cpp/AdventHelpers/AdventHelpers.vcxproj.filters @@ -21,6 +21,9 @@ source + + source + diff --git a/2025/Cpp/AdventHelpers/include/AdventHelpers/AdventOfCodeSolution.h b/2025/Cpp/AdventHelpers/include/AdventHelpers/AdventOfCodeSolution.h index e5ac008..648fe29 100644 --- a/2025/Cpp/AdventHelpers/include/AdventHelpers/AdventOfCodeSolution.h +++ b/2025/Cpp/AdventHelpers/include/AdventHelpers/AdventOfCodeSolution.h @@ -13,43 +13,7 @@ namespace AdventHelpers inline AdventHelpers::InputFileHelper* GetExampleInputFile(); inline AdventHelpers::InputFileHelper* GetProblemInputFile(); - void SolveAll() { - auto* exampleInput = GetExampleInputFile(); - if (!exampleInput) { - std::cerr << "Failed to load example input file." << std::endl; - return; - } - - auto* problemInput = GetProblemInputFile(); - if (!problemInput) { - std::cerr << "Failed to load problem input file." << std::endl; - AdventHelpers::InputFileHelper::destroy(exampleInput); - return; - } - - // Problem 01, example input - std::cout << "Solving problem 01 using example input..." << std::endl; - auto exampleResult01 = SolveProblem01(*exampleInput); - std::cout << "|- Got result: " << exampleResult01 << std::endl; - - // Problem 01, puzzle input - std::cout << "Solving problem 01 using puzzle input..." << std::endl; - auto problemResult01 = SolveProblem01(*problemInput); - std::cout << "|- Got result: " << problemResult01 << std::endl; - - // Problem 02, example input - std::cout << "Solving problem 02 using example input..." << std::endl; - auto exampleResult02 = SolveProblem02(*exampleInput); - std::cout << "|- Got result: " << exampleResult02 << std::endl; - - // Problem 02, puzzle input - std::cout << "Solving problem 02 using puzzle input..." << std::endl; - auto problemResult02 = SolveProblem02(*problemInput); - std::cout << "|- Got result: " << problemResult02 << std::endl; - - AdventHelpers::InputFileHelper::destroy(exampleInput); - AdventHelpers::InputFileHelper::destroy(problemInput); - } + void SolveAll(); }; AdventHelpers::InputFileHelper* AdventOfCodeSolution::GetExampleInputFile() { diff --git a/2025/Cpp/AdventHelpers/source/AdventOfCodeSolution.cpp b/2025/Cpp/AdventHelpers/source/AdventOfCodeSolution.cpp new file mode 100644 index 0000000..c27798a --- /dev/null +++ b/2025/Cpp/AdventHelpers/source/AdventOfCodeSolution.cpp @@ -0,0 +1,47 @@ +#include "AdventHelpers/AdventOfCodeSolution.h" + +namespace AdventHelpers +{ + void AdventOfCodeSolution::SolveAll() { + try { + auto* exampleInput = GetExampleInputFile(); + if (!exampleInput) { + std::cerr << "Failed to load example input file." << std::endl; + return; + } + + auto* problemInput = GetProblemInputFile(); + if (!problemInput) { + std::cerr << "Failed to load problem input file." << std::endl; + AdventHelpers::InputFileHelper::destroy(exampleInput); + return; + } + + // Problem 01, example input + std::cout << "Solving problem 01 using example input..." << std::endl; + auto exampleResult01 = SolveProblem01(*exampleInput); + std::cout << "|- Got result: " << exampleResult01 << std::endl; + + // Problem 01, puzzle input + std::cout << "Solving problem 01 using puzzle input..." << std::endl; + auto problemResult01 = SolveProblem01(*problemInput); + std::cout << "|- Got result: " << problemResult01 << std::endl; + + // Problem 02, example input + std::cout << "Solving problem 02 using example input..." << std::endl; + auto exampleResult02 = SolveProblem02(*exampleInput); + std::cout << "|- Got result: " << exampleResult02 << std::endl; + + // Problem 02, puzzle input + std::cout << "Solving problem 02 using puzzle input..." << std::endl; + auto problemResult02 = SolveProblem02(*problemInput); + std::cout << "|- Got result: " << problemResult02 << std::endl; + + AdventHelpers::InputFileHelper::destroy(exampleInput); + AdventHelpers::InputFileHelper::destroy(problemInput); + } + catch (...) { + std::cerr << "An unexpected error occurred while solving the problems." << std::endl; + } + } +} // namespace AdventHelpers \ No newline at end of file