Solution for Day 1 in C++
This commit is contained in:
@@ -1,13 +1,62 @@
|
||||
#pragma once
|
||||
|
||||
#include "AdventHelpers/InputFileHelper.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace AdventHelpers
|
||||
{
|
||||
class IAdventOfCodeSolution {
|
||||
class AdventOfCodeSolution {
|
||||
public:
|
||||
virtual void SolveExample(AdventHelper::InputFileHelper& inputFile) = 0;
|
||||
virtual void SolveProblem01(AdventHelper::InputFileHelper& inputFile) = 0;
|
||||
virtual void SolveProblem02(AdventHelper::InputFileHelper& inputFile) = 0;
|
||||
virtual std::string SolveProblem01(AdventHelpers::InputFileHelper& inputFile) = 0;
|
||||
virtual std::string SolveProblem02(AdventHelpers::InputFileHelper& inputFile) = 0;
|
||||
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
AdventHelpers::InputFileHelper* AdventOfCodeSolution::GetExampleInputFile() {
|
||||
return AdventHelpers::InputFileHelper::create("example-input.txt");
|
||||
}
|
||||
|
||||
AdventHelpers::InputFileHelper* AdventOfCodeSolution::GetProblemInputFile() {
|
||||
return AdventHelpers::InputFileHelper::create("puzzle-input.txt");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace AdventHelper {
|
||||
namespace AdventHelpers {
|
||||
// Interface
|
||||
class InputFileHelper {
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user