Small refactor for solution class
This commit is contained in:
@@ -155,6 +155,7 @@
|
|||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClCompile Include="source\AdventOfCodeSolution.cpp" />
|
||||||
<ClCompile Include="source\InputFileHelper.cpp" />
|
<ClCompile Include="source\InputFileHelper.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -21,6 +21,9 @@
|
|||||||
<ClCompile Include="source\InputFileHelper.cpp">
|
<ClCompile Include="source\InputFileHelper.cpp">
|
||||||
<Filter>source</Filter>
|
<Filter>source</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="source\AdventOfCodeSolution.cpp">
|
||||||
|
<Filter>source</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="include\AdventHelpers\InputFileHelper.h">
|
<ClInclude Include="include\AdventHelpers\InputFileHelper.h">
|
||||||
|
|||||||
@@ -13,43 +13,7 @@ namespace AdventHelpers
|
|||||||
inline AdventHelpers::InputFileHelper* GetExampleInputFile();
|
inline AdventHelpers::InputFileHelper* GetExampleInputFile();
|
||||||
inline AdventHelpers::InputFileHelper* GetProblemInputFile();
|
inline AdventHelpers::InputFileHelper* GetProblemInputFile();
|
||||||
|
|
||||||
void SolveAll() {
|
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);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
AdventHelpers::InputFileHelper* AdventOfCodeSolution::GetExampleInputFile() {
|
AdventHelpers::InputFileHelper* AdventOfCodeSolution::GetExampleInputFile() {
|
||||||
|
|||||||
47
2025/Cpp/AdventHelpers/source/AdventOfCodeSolution.cpp
Normal file
47
2025/Cpp/AdventHelpers/source/AdventOfCodeSolution.cpp
Normal file
@@ -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
|
||||||
Reference in New Issue
Block a user