Add proper CMake setup and update project structure
This commit is contained in:
parent
fdfdca84e4
commit
38bca1e549
|
@ -0,0 +1,37 @@
|
|||
# Sources
|
||||
*.c text diff=cpp
|
||||
*.cc text diff=cpp
|
||||
*.cxx text diff=cpp
|
||||
*.cpp text diff=cpp
|
||||
*.cpi text diff=cpp
|
||||
*.c++ text diff=cpp
|
||||
*.hpp text diff=cpp
|
||||
*.h text diff=cpp
|
||||
*.h++ text diff=cpp
|
||||
*.hh text diff=cpp
|
||||
|
||||
# Compiled Object files
|
||||
*.slo binary
|
||||
*.lo binary
|
||||
*.o binary
|
||||
*.obj binary
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch binary
|
||||
*.pch binary
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
*.so binary
|
||||
*.dylib binary
|
||||
*.dll binary
|
||||
|
||||
# Compiled Static libraries
|
||||
*.lai binary
|
||||
*.la binary
|
||||
*.a binary
|
||||
*.lib binary
|
||||
|
||||
# Executables
|
||||
*.exe binary
|
||||
*.out binary
|
||||
*.app binary
|
|
@ -35,5 +35,5 @@
|
|||
# VS and Output
|
||||
.vs
|
||||
Debug/
|
||||
out/
|
||||
*.vcxproj.user
|
||||
*.vcxproj.user
|
||||
build/
|
|
@ -1,4 +1,4 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
|
@ -13,7 +13,7 @@
|
|||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "AdventOfCode2024.h"
|
||||
#include <aoc/Program.h>
|
||||
|
||||
int main()
|
||||
{
|
|
@ -1,82 +0,0 @@
|
|||
# Visual Studio generated .editorconfig file with C++ settings.
|
||||
root = true
|
||||
|
||||
[*.{c++,cc,cpp,cppm,cxx,h,h++,hh,hpp,hxx,inl,ipp,ixx,tlh,tli}]
|
||||
|
||||
# Visual C++ Code Style settings
|
||||
|
||||
cpp_generate_documentation_comments = xml
|
||||
|
||||
# Visual C++ Formatting settings
|
||||
|
||||
cpp_indent_braces = false
|
||||
cpp_indent_multi_line_relative_to = innermost_parenthesis
|
||||
cpp_indent_within_parentheses = indent
|
||||
cpp_indent_preserve_within_parentheses = true
|
||||
cpp_indent_case_contents = true
|
||||
cpp_indent_case_labels = true
|
||||
cpp_indent_case_contents_when_block = false
|
||||
cpp_indent_lambda_braces_when_parameter = true
|
||||
cpp_indent_goto_labels = one_left
|
||||
cpp_indent_preprocessor = leftmost_column
|
||||
cpp_indent_access_specifiers = false
|
||||
cpp_indent_namespace_contents = true
|
||||
cpp_indent_preserve_comments = false
|
||||
cpp_new_line_before_open_brace_namespace = ignore
|
||||
cpp_new_line_before_open_brace_type = ignore
|
||||
cpp_new_line_before_open_brace_function = ignore
|
||||
cpp_new_line_before_open_brace_block = ignore
|
||||
cpp_new_line_before_open_brace_lambda = ignore
|
||||
cpp_new_line_scope_braces_on_separate_lines = false
|
||||
cpp_new_line_close_brace_same_line_empty_type = false
|
||||
cpp_new_line_close_brace_same_line_empty_function = false
|
||||
cpp_new_line_before_catch = true
|
||||
cpp_new_line_before_else = true
|
||||
cpp_new_line_before_while_in_do_while = false
|
||||
cpp_space_before_function_open_parenthesis = remove
|
||||
cpp_space_within_parameter_list_parentheses = false
|
||||
cpp_space_between_empty_parameter_list_parentheses = false
|
||||
cpp_space_after_keywords_in_control_flow_statements = true
|
||||
cpp_space_within_control_flow_statement_parentheses = false
|
||||
cpp_space_before_lambda_open_parenthesis = false
|
||||
cpp_space_within_cast_parentheses = false
|
||||
cpp_space_after_cast_close_parenthesis = false
|
||||
cpp_space_within_expression_parentheses = false
|
||||
cpp_space_before_block_open_brace = true
|
||||
cpp_space_between_empty_braces = false
|
||||
cpp_space_before_initializer_list_open_brace = false
|
||||
cpp_space_within_initializer_list_braces = true
|
||||
cpp_space_preserve_in_initializer_list = true
|
||||
cpp_space_before_open_square_bracket = false
|
||||
cpp_space_within_square_brackets = false
|
||||
cpp_space_before_empty_square_brackets = false
|
||||
cpp_space_between_empty_square_brackets = false
|
||||
cpp_space_group_square_brackets = true
|
||||
cpp_space_within_lambda_brackets = false
|
||||
cpp_space_between_empty_lambda_brackets = false
|
||||
cpp_space_before_comma = false
|
||||
cpp_space_after_comma = true
|
||||
cpp_space_remove_around_member_operators = true
|
||||
cpp_space_before_inheritance_colon = true
|
||||
cpp_space_before_constructor_colon = true
|
||||
cpp_space_remove_before_semicolon = true
|
||||
cpp_space_after_semicolon = true
|
||||
cpp_space_remove_around_unary_operator = true
|
||||
cpp_space_around_binary_operator = insert
|
||||
cpp_space_around_assignment_operator = insert
|
||||
cpp_space_pointer_reference_alignment = left
|
||||
cpp_space_around_ternary_operator = insert
|
||||
cpp_use_unreal_engine_macro_formatting = true
|
||||
cpp_wrap_preserve_blocks = one_liners
|
||||
|
||||
# Visual C++ Inlcude Cleanup settings
|
||||
|
||||
cpp_include_cleanup_add_missing_error_tag_type = suggestion
|
||||
cpp_include_cleanup_remove_unused_error_tag_type = dimmed
|
||||
cpp_include_cleanup_optimize_unused_error_tag_type = suggestion
|
||||
cpp_include_cleanup_sort_after_edits = false
|
||||
cpp_sort_includes_error_tag_type = none
|
||||
cpp_sort_includes_priority_case_sensitive = false
|
||||
cpp_sort_includes_priority_style = quoted
|
||||
cpp_includes_style = default
|
||||
cpp_includes_use_forward_slash = true
|
|
@ -1,18 +0,0 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
// Foundation, either version 3 of the License, or (at your option) any later
|
||||
// version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Program.h"
|
|
@ -1,21 +0,0 @@
|
|||
# CMakeList.txt : CMake project for AdventOfCode2024, include source and define
|
||||
# project specific logic here.
|
||||
#
|
||||
cmake_minimum_required (VERSION 3.8)
|
||||
|
||||
# Enable Hot Reload for MSVC compilers if supported.
|
||||
if (POLICY CMP0141)
|
||||
cmake_policy(SET CMP0141 NEW)
|
||||
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<IF:$<AND:$<C_COMPILER_ID:MSVC>,$<CXX_COMPILER_ID:MSVC>>,$<$<CONFIG:Debug,RelWithDebInfo>:EditAndContinue>,$<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>>")
|
||||
endif()
|
||||
|
||||
project ("AdventOfCode2024")
|
||||
|
||||
# Add source to this project's executable.
|
||||
add_executable (AdventOfCode2024 "AdventOfCode2024.cpp" "AdventOfCode2024.h")
|
||||
|
||||
if (CMAKE_VERSION VERSION_GREATER 3.12)
|
||||
set_property(TARGET AdventOfCode2024 PROPERTY CXX_STANDARD 20)
|
||||
endif()
|
||||
|
||||
# TODO: Add tests and install targets if needed.
|
|
@ -1,61 +0,0 @@
|
|||
{
|
||||
"version": 3,
|
||||
"configurePresets": [
|
||||
{
|
||||
"name": "windows-base",
|
||||
"hidden": true,
|
||||
"generator": "Ninja",
|
||||
"binaryDir": "${sourceDir}/out/build/${presetName}",
|
||||
"installDir": "${sourceDir}/out/install/${presetName}",
|
||||
"cacheVariables": {
|
||||
"CMAKE_C_COMPILER": "cl.exe",
|
||||
"CMAKE_CXX_COMPILER": "cl.exe"
|
||||
},
|
||||
"condition": {
|
||||
"type": "equals",
|
||||
"lhs": "${hostSystemName}",
|
||||
"rhs": "Windows"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "x64-debug",
|
||||
"displayName": "x64 Debug",
|
||||
"inherits": "windows-base",
|
||||
"architecture": {
|
||||
"value": "x64",
|
||||
"strategy": "external"
|
||||
},
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Debug"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "x64-release",
|
||||
"displayName": "x64 Release",
|
||||
"inherits": "x64-debug",
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Release"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "x86-debug",
|
||||
"displayName": "x86 Debug",
|
||||
"inherits": "windows-base",
|
||||
"architecture": {
|
||||
"value": "x86",
|
||||
"strategy": "external"
|
||||
},
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Debug"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "x86-release",
|
||||
"displayName": "x86 Release",
|
||||
"inherits": "x86-debug",
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Release"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,80 +0,0 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
// Foundation, either version 3 of the License, or (at your option) any later
|
||||
// version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "CeresSearch.h"
|
||||
|
||||
std::string CeresSearch::getPuzzleName() const
|
||||
{
|
||||
return "Day 4: Ceres Search";
|
||||
}
|
||||
|
||||
std::string CeresSearch::getInputFileName() const
|
||||
{
|
||||
return "ceres_search.txt";
|
||||
}
|
||||
|
||||
void CeresSearch::finish()
|
||||
{
|
||||
for (int j = 0; j < lines.size(); j++)
|
||||
{
|
||||
for (int i = 0; i < lines[j].size(); i++)
|
||||
{
|
||||
if (lines[j][i] == xmas[0])
|
||||
{
|
||||
Point2 start{ i, j };
|
||||
computeXmasCount(start);
|
||||
}
|
||||
else if (lines[j][i] == xmas[2])
|
||||
{
|
||||
Point2 start{ i, j };
|
||||
computeX_MasCount(start);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CeresSearch::computeXmasCount(const Point2& start)
|
||||
{
|
||||
for (auto d : Point2::directions)
|
||||
{
|
||||
auto p{ start + d };
|
||||
auto i{ 1 };
|
||||
while (i < 4 && isInBounds(p) && xmas[i] == getPosition(p))
|
||||
{
|
||||
p += d;
|
||||
i++;
|
||||
}
|
||||
if (i == 4)
|
||||
{
|
||||
part1++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CeresSearch::computeX_MasCount(const Point2& start)
|
||||
{
|
||||
auto pUL{ start + Point2::upLeft };
|
||||
auto pDR{ start + Point2::downRight };
|
||||
auto pUR{ start + Point2::upRight };
|
||||
auto pDL{ start + Point2::downLeft };
|
||||
if (isInBounds(pUL) && isInBounds(pDR)
|
||||
&& ((getPosition(pUL) == xmas[1] && getPosition(pDR) == xmas[3])
|
||||
|| (getPosition(pUL) == xmas[3] && getPosition(pDR) == xmas[1]))
|
||||
&& ((getPosition(pUR) == xmas[1] && getPosition(pDL) == xmas[3])
|
||||
|| (getPosition(pUR) == xmas[3] && getPosition(pDL) == xmas[1])))
|
||||
{
|
||||
part2++;
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
// Foundation, either version 3 of the License, or (at your option) any later
|
||||
// version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "LinesSolver.h"
|
||||
|
||||
class CeresSearch :
|
||||
public LinesSolver
|
||||
{
|
||||
public:
|
||||
std::string getPuzzleName() const override;
|
||||
std::string getInputFileName() const override;
|
||||
void finish() override;
|
||||
private:
|
||||
char xmas[4] = { 'X', 'M', 'A', 'S' };
|
||||
void computeXmasCount(const Point2& start);
|
||||
void computeX_MasCount(const Point2& start);
|
||||
};
|
|
@ -1,32 +0,0 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
// Foundation, either version 3 of the License, or (at your option) any later
|
||||
// version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "LinesSolver.h"
|
||||
|
||||
void LinesSolver::processDataLine(const std::string& line)
|
||||
{
|
||||
lines.push_back(line);
|
||||
}
|
||||
|
||||
bool LinesSolver::isInBounds(const Point2& point)
|
||||
{
|
||||
return 0 <= point.y && point.y < lines.size()
|
||||
&& 0 <= point.x && point.x < lines[point.y].size();
|
||||
}
|
||||
|
||||
char LinesSolver::getPosition(const Point2& point)
|
||||
{
|
||||
return lines[point.y][point.x];
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
// Foundation, either version 3 of the License, or (at your option) any later
|
||||
// version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "Solver.h"
|
||||
#include "Point2.h"
|
||||
|
||||
class LinesSolver :
|
||||
public Solver
|
||||
{
|
||||
public:
|
||||
void processDataLine(const std::string& line) override;
|
||||
protected:
|
||||
std::vector<std::string> lines{};
|
||||
bool isInBounds(const Point2& point);
|
||||
char getPosition(const Point2& point);
|
||||
};
|
|
@ -1,81 +0,0 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
// Foundation, either version 3 of the License, or (at your option) any later
|
||||
// version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "Point2.h"
|
||||
|
||||
Point2::Point2()
|
||||
: Point2{ 0, 0 } {}
|
||||
|
||||
Point2::Point2(const int x, const int y)
|
||||
: x{ x }, y{ y } {}
|
||||
|
||||
bool Point2::operator==(const Point2& rhs) const
|
||||
{
|
||||
return x == rhs.x && y == rhs.y;
|
||||
}
|
||||
|
||||
bool Point2::operator!=(const Point2& rhs) const
|
||||
{
|
||||
return !(x == y);
|
||||
}
|
||||
|
||||
Point2 Point2::operator+(const Point2& rhs) const
|
||||
{
|
||||
return Point2(x + rhs.x, y + rhs.y);
|
||||
}
|
||||
|
||||
Point2 Point2::operator-(const Point2& rhs) const
|
||||
{
|
||||
return Point2(x - rhs.x, y - rhs.y);
|
||||
}
|
||||
|
||||
Point2 Point2::operator*(const int rhs) const
|
||||
{
|
||||
return Point2(x * rhs, y * rhs);
|
||||
}
|
||||
|
||||
Point2 Point2::operator-() const
|
||||
{
|
||||
return Point2(-x, -y);
|
||||
}
|
||||
|
||||
Point2& Point2::operator+=(const Point2& rhs)
|
||||
{
|
||||
*this = *this + rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Point2& Point2::operator-=(const Point2& rhs)
|
||||
{
|
||||
*this = *this - rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Point2& Point2::operator*=(const int rhs)
|
||||
{
|
||||
*this = *this * rhs;
|
||||
return *this;
|
||||
}
|
||||
|
||||
const Point2 Point2::left{ -1, 0 };
|
||||
const Point2 Point2::right{ 1, 0 };
|
||||
const Point2 Point2::up{ 0, -1 };
|
||||
const Point2 Point2::down{ 0, 1 };
|
||||
const Point2 Point2::upLeft{ -1, -1 };
|
||||
const Point2 Point2::upRight{ 1, -1 };
|
||||
const Point2 Point2::downLeft{ -1, 1 };
|
||||
const Point2 Point2::downRight{ 1, 1 };
|
||||
const Point2 Point2::directions[] = { Point2::left, Point2::right, Point2::up, Point2::down,
|
||||
Point2::upLeft, Point2::upRight, Point2::downLeft, Point2::downRight };
|
|
@ -1,36 +0,0 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
// Foundation, either version 3 of the License, or (at your option) any later
|
||||
// version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
class Point2
|
||||
{
|
||||
public:
|
||||
int x, y;
|
||||
Point2();
|
||||
Point2(const int x, const int y);
|
||||
bool operator==(const Point2& rhs) const;
|
||||
bool operator!=(const Point2& rhs) const;
|
||||
Point2 operator+(const Point2& rhs) const;
|
||||
Point2 operator-(const Point2& rhs) const;
|
||||
Point2 operator*(const int rhs) const;
|
||||
Point2 operator-() const;
|
||||
Point2& operator+=(const Point2& rhs);
|
||||
Point2& operator-=(const Point2& rhs);
|
||||
Point2& operator*=(const int rhs);
|
||||
static const Point2 left, right, up, down;
|
||||
static const Point2 upLeft, upRight, downLeft, downRight;
|
||||
static const Point2 directions[8];
|
||||
};
|
|
@ -1 +0,0 @@
|
|||
#include "StringState.h"
|
|
@ -1,82 +0,0 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
// Foundation, either version 3 of the License, or (at your option) any later
|
||||
// version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "pch.h"
|
||||
#include "CppUnitTest.h"
|
||||
|
||||
#include "Part1TestContext.h"
|
||||
#include "Part2TestContext.h"
|
||||
#include "../Solver.h"
|
||||
#include "../SolverEngine.h"
|
||||
|
||||
#include "../HistorianHysteria.h"
|
||||
|
||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
|
||||
namespace UnitTests
|
||||
{
|
||||
TEST_CLASS(HistorianHysteriaTests)
|
||||
{
|
||||
public:
|
||||
TEST_METHOD(FullData1)
|
||||
{
|
||||
runTest(*std::make_unique<HistorianHysteria>(), 2176849, part1TestContext_);
|
||||
}
|
||||
|
||||
TEST_METHOD(FullData2)
|
||||
{
|
||||
runTest(*std::make_unique<HistorianHysteria>(), 23384288, part2TestContext_);
|
||||
}
|
||||
|
||||
TEST_METHOD(ExampleData1)
|
||||
{
|
||||
runTest(*std::make_unique<HistorianHysteria>(), 11, part1ExampleTestContext_);
|
||||
}
|
||||
|
||||
TEST_METHOD(ExampleData2)
|
||||
{
|
||||
runTest(*std::make_unique<HistorianHysteria>(), 31, part2ExampleTestContext_);
|
||||
}
|
||||
|
||||
private:
|
||||
Part1TestContext part1TestContext_{ getInputPaths() };
|
||||
Part2TestContext part2TestContext_{ getInputPaths() };
|
||||
Part1TestContext part1ExampleTestContext_{ getExampleInputPaths() };
|
||||
Part2TestContext part2ExampleTestContext_{ getExampleInputPaths() };
|
||||
|
||||
void runTest(Solver& solver, const long long int expected, const TestContext& context)
|
||||
{
|
||||
SolverEngine solverEngine{ context.getInputPaths() };
|
||||
solverEngine.run(solver);
|
||||
assertAreEqual(expected, context.getResult(solver));
|
||||
}
|
||||
|
||||
std::vector<std::string> getInputPaths() const
|
||||
{
|
||||
return std::vector<std::string>{ "../../data", "../../../../data" };
|
||||
}
|
||||
|
||||
std::vector<std::string> getExampleInputPaths() const
|
||||
{
|
||||
return std::vector<std::string>{ "../../data/examples", "../../../../data/examples" };
|
||||
}
|
||||
|
||||
void assertAreEqual(const long long int expected, const long long int actual) const
|
||||
{
|
||||
std::wstring message = L"Expected: <" + std::to_wstring(expected) + L"> Actual: <" + std::to_wstring(actual) + L">";
|
||||
Assert::IsTrue(expected == actual, message.c_str());
|
||||
}
|
||||
};
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
|
||||
Include(FetchContent)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 23) # latest c++
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
# prepare out unit test framework
|
||||
FetchContent_Declare(
|
||||
Catch2
|
||||
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
|
||||
GIT_TAG v3.4.0 # or a later release
|
||||
)
|
||||
FetchContent_MakeAvailable(Catch2)
|
||||
|
||||
# Versioning
|
||||
project ("AdventOfCode2024" VERSION 0.0.1 DESCRIPTION "" LANGUAGES CXX)
|
||||
# ---
|
||||
|
||||
# Grab source files
|
||||
file(GLOB_RECURSE AdventOfCode2024Sources
|
||||
"include/*.h"
|
||||
"include/*.hpp"
|
||||
"src/*.c"
|
||||
"src/*.cpp"
|
||||
)
|
||||
file(GLOB_RECURSE AdventOfCode2024Tests
|
||||
"tests/include/*.h"
|
||||
"tests/include/*.hpp"
|
||||
"tests/src/*.c"
|
||||
"tests/src/*.cpp"
|
||||
)
|
||||
|
||||
# Project setup
|
||||
set(output_target AdventOfCode2024)
|
||||
|
||||
# This is split in 2 because catch2 generates its own main() functions
|
||||
# and we don't want to recompile everything twice, so we reuse the lib object.
|
||||
# lib
|
||||
# / \
|
||||
# main exe catch2
|
||||
|
||||
# Library to contain logic/code
|
||||
add_library(${output_target}-lib ${AdventOfCode2024Sources})
|
||||
target_include_directories(${output_target}-lib PUBLIC "include")
|
||||
|
||||
# Executable that links to the lib containing the code
|
||||
add_executable(${output_target} "AdventOfCode2024.cpp")
|
||||
target_link_libraries(${output_target} PRIVATE ${output_target}-lib)
|
||||
|
||||
# Catch2 linked with the lib.
|
||||
add_executable(${output_target}-tests ${AdventOfCode2024Tests})
|
||||
target_include_directories(${output_target}-tests PRIVATE "tests/include")
|
||||
target_link_libraries(${output_target}-tests PRIVATE
|
||||
${output_target}-lib
|
||||
Catch2::Catch2WithMain
|
||||
)
|
|
@ -1,5 +1,5 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -17,10 +17,10 @@
|
|||
|
||||
#include <set>
|
||||
|
||||
#include "Solver.h"
|
||||
#include <aoc/Solver.h>
|
||||
|
||||
class HistorianHysteria :
|
||||
public Solver
|
||||
class HistorianHysteria
|
||||
: public Solver
|
||||
{
|
||||
public:
|
||||
virtual std::string getPuzzleName() const override;
|
|
@ -1,5 +1,5 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -15,10 +15,10 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "StringState.h"
|
||||
#include <aoc/StringState.h>
|
||||
|
||||
class MullCharState :
|
||||
public StringState
|
||||
class MullCharState
|
||||
: public StringState
|
||||
{
|
||||
public:
|
||||
MullCharState(const char expected);
|
|
@ -1,5 +1,5 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
|
@ -1,5 +1,5 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -15,11 +15,11 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "MullData.h"
|
||||
#include "StringState.h"
|
||||
#include <aoc/MullData.h>
|
||||
#include <aoc/StringState.h>
|
||||
|
||||
class MullDataState :
|
||||
public StringState
|
||||
class MullDataState
|
||||
: public StringState
|
||||
{
|
||||
public:
|
||||
void setData(MullData& data);
|
|
@ -1,5 +1,5 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -15,10 +15,10 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "MullDataState.h"
|
||||
#include <aoc/MullDataState.h>
|
||||
|
||||
class MullDoOpenState :
|
||||
public MullDataState
|
||||
class MullDoOpenState
|
||||
: public MullDataState
|
||||
{
|
||||
public:
|
||||
void enter(StringStateMachine* stateMachine) override {};
|
|
@ -1,5 +1,5 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -15,10 +15,10 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "StringState.h"
|
||||
#include <aoc/StringState.h>
|
||||
|
||||
class MullEntryState :
|
||||
public StringState
|
||||
class MullEntryState
|
||||
: public StringState
|
||||
{
|
||||
public:
|
||||
void enter(StringStateMachine* stateMachine) override;
|
|
@ -1,5 +1,5 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -15,10 +15,10 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "MullDataState.h"
|
||||
#include <aoc/MullDataState.h>
|
||||
|
||||
class MullFactorState :
|
||||
public MullDataState
|
||||
class MullFactorState
|
||||
: public MullDataState
|
||||
{
|
||||
public:
|
||||
MullFactorState(const char expected, const int index);
|
|
@ -1,5 +1,5 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -15,12 +15,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "MullData.h"
|
||||
#include "MullStates.h"
|
||||
#include "Solver.h"
|
||||
#include <aoc/MullData.h>
|
||||
#include <aoc/MullStates.h>
|
||||
#include <aoc/Solver.h>
|
||||
|
||||
class MullItOver :
|
||||
public Solver
|
||||
class MullItOver
|
||||
: public Solver
|
||||
{
|
||||
public:
|
||||
MullItOver();
|
|
@ -1,5 +1,5 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -15,11 +15,11 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "MullCharState.h"
|
||||
#include "MullDoOpenState.h"
|
||||
#include "MullEntryState.h"
|
||||
#include "MullFactorState.h"
|
||||
#include "MullToggleCloseState.h"
|
||||
#include <aoc/MullCharState.h>
|
||||
#include <aoc/MullDoOpenState.h>
|
||||
#include <aoc/MullEntryState.h>
|
||||
#include <aoc/MullFactorState.h>
|
||||
#include <aoc/MullToggleCloseState.h>
|
||||
|
||||
class MullStates
|
||||
{
|
|
@ -1,5 +1,5 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -15,10 +15,10 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "MullDataState.h"
|
||||
#include <aoc/MullDataState.h>
|
||||
|
||||
class MullToggleCloseState :
|
||||
public MullDataState
|
||||
class MullToggleCloseState
|
||||
: public MullDataState
|
||||
{
|
||||
public:
|
||||
MullToggleCloseState(const bool isEnabler);
|
|
@ -1,5 +1,5 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
|
@ -1,5 +1,5 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -17,7 +17,7 @@
|
|||
|
||||
#include<vector>
|
||||
|
||||
#include "Slope.h"
|
||||
#include <aoc/Slope.h>
|
||||
|
||||
class RedNosedReportData
|
||||
{
|
|
@ -1,5 +1,5 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -15,12 +15,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "Slope.h"
|
||||
#include "Solver.h"
|
||||
#include "RedNosedReportData.h"
|
||||
#include <aoc/Slope.h>
|
||||
#include <aoc/Solver.h>
|
||||
#include <aoc/RedNosedReportData.h>
|
||||
|
||||
class RedNosedReports :
|
||||
public Solver
|
||||
class RedNosedReports
|
||||
: public Solver
|
||||
{
|
||||
public:
|
||||
std::string getPuzzleName() const override;
|
|
@ -1,5 +1,5 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
|
@ -1,5 +1,5 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -21,10 +21,10 @@ class Solver
|
|||
{
|
||||
public:
|
||||
Solver();
|
||||
virtual ~Solver() {};
|
||||
virtual ~Solver(){};
|
||||
virtual std::string getPuzzleName() const = 0;
|
||||
virtual std::string getInputFileName() const = 0;
|
||||
virtual void processDataLine(const std::string& line) = 0;
|
||||
virtual void processDataLine(const std::string &line) = 0;
|
||||
virtual void finish() = 0;
|
||||
long long int getResultPart1() const;
|
||||
long long int getResultPart2() const;
|
|
@ -1,5 +1,5 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -20,13 +20,14 @@
|
|||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "Solver.h"
|
||||
#include <aoc/Solver.h>
|
||||
|
||||
class SolverEngine
|
||||
{
|
||||
public:
|
||||
SolverEngine(const std::vector<std::string>& inputPaths);
|
||||
void run(Solver& solver);
|
||||
|
||||
private:
|
||||
std::vector<std::string> inputPaths_;
|
||||
std::filesystem::path tryGetValidFullInputFilePath(const std::string& inputFileName);
|
|
@ -1,5 +1,5 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -17,7 +17,7 @@
|
|||
|
||||
#include <vector>
|
||||
|
||||
#include "StringStateMachine.h"
|
||||
#include <aoc/StringStateMachine.h>
|
||||
|
||||
class StringStateMachine;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -17,7 +17,7 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
#include "StringState.h"
|
||||
#include <aoc/StringState.h>
|
||||
|
||||
class StringState;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -15,7 +15,7 @@
|
|||
|
||||
#include <iostream>
|
||||
|
||||
#include "HistorianHysteria.h"
|
||||
#include <aoc/HistorianHysteria.h>
|
||||
|
||||
std::string HistorianHysteria::getPuzzleName() const
|
||||
{
|
|
@ -1,5 +1,5 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -13,7 +13,7 @@
|
|||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "MullCharState.h"
|
||||
#include <aoc/MullCharState.h>
|
||||
|
||||
MullCharState::MullCharState(const char expected)
|
||||
: expected_{ expected }, successState_{}, failState_{} {}
|
|
@ -1,5 +1,5 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -13,7 +13,7 @@
|
|||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "MullData.h"
|
||||
#include <aoc/MullData.h>
|
||||
|
||||
MullData::MullData()
|
||||
: isEnabled_{ true }, factor1_{ 0 }, factor2_{ 0 }, part1_{ 0 }, part2_{ 0 } {};
|
|
@ -1,5 +1,5 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -13,7 +13,7 @@
|
|||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "MullDataState.h"
|
||||
#include <aoc/MullDataState.h>
|
||||
|
||||
void MullDataState::setData(MullData& data)
|
||||
{
|
|
@ -1,5 +1,5 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -13,7 +13,7 @@
|
|||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "MullDoOpenState.h"
|
||||
#include <aoc/MullDoOpenState.h>
|
||||
|
||||
void MullDoOpenState::next(StringStateMachine* stateMachine)
|
||||
{
|
|
@ -1,5 +1,5 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -13,7 +13,7 @@
|
|||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "MullEntryState.h"
|
||||
#include <aoc/MullEntryState.h>
|
||||
|
||||
void MullEntryState::enter(StringStateMachine* stateMachine)
|
||||
{
|
|
@ -1,5 +1,5 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -13,7 +13,7 @@
|
|||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "MullFactorState.h"
|
||||
#include <aoc/MullFactorState.h>
|
||||
|
||||
MullFactorState::MullFactorState(const char expected, const int index)
|
||||
: expected_{ expected }, index_{ index }, successState_{}, failState_{} {}
|
|
@ -1,5 +1,5 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -13,8 +13,8 @@
|
|||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "MullItOver.h"
|
||||
#include "StringStateMachine.h"
|
||||
#include <aoc/MullItOver.h>
|
||||
#include <aoc/StringStateMachine.h>
|
||||
|
||||
MullItOver::MullItOver()
|
||||
: Solver{}, data_{}, states_ {
|
|
@ -1,5 +1,5 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -13,7 +13,7 @@
|
|||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "MullStates.h"
|
||||
#include <aoc/MullStates.h>
|
||||
|
||||
MullStates::MullStates(MullData& data)
|
||||
{
|
|
@ -1,5 +1,5 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -13,7 +13,7 @@
|
|||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "MullToggleCloseState.h"
|
||||
#include <aoc/MullToggleCloseState.h>
|
||||
|
||||
MullToggleCloseState::MullToggleCloseState(const bool isEnabler)
|
||||
: isEnabler_{ isEnabler }, successState_{} {}
|
|
@ -1,5 +1,5 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -16,14 +16,13 @@
|
|||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
#include "Program.h"
|
||||
#include "SolverEngine.h"
|
||||
#include <aoc/Program.h>
|
||||
#include <aoc/SolverEngine.h>
|
||||
|
||||
// Solver implementations in day order.
|
||||
#include "HistorianHysteria.h"
|
||||
#include "RedNosedReports.h"
|
||||
#include "MullItOver.h"
|
||||
#include "CeresSearch.h"
|
||||
#include <aoc/HistorianHysteria.h>
|
||||
#include <aoc/RedNosedReports.h>
|
||||
#include <aoc/MullItOver.h>
|
||||
|
||||
void Program::run()
|
||||
{
|
||||
|
@ -37,10 +36,9 @@ void Program::runSolvers()
|
|||
solverEngine.run(*std::make_unique<HistorianHysteria>());
|
||||
solverEngine.run(*std::make_unique<RedNosedReports>());
|
||||
solverEngine.run(*std::make_unique<MullItOver>());
|
||||
solverEngine.run(*std::make_unique<CeresSearch>());
|
||||
}
|
||||
|
||||
std::vector<std::string> Program::getInputPaths() const
|
||||
{
|
||||
return std::vector<std::string>{ "data", "../../data" };
|
||||
return std::vector<std::string>{ "data", "../../../data", "../../../../data" };
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -17,7 +17,7 @@
|
|||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
#include "RedNosedReports.h"
|
||||
#include <aoc/RedNosedReports.h>
|
||||
|
||||
std::string RedNosedReports::getPuzzleName() const
|
||||
{
|
|
@ -1,5 +1,5 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -13,7 +13,7 @@
|
|||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "Solver.h"
|
||||
#include <aoc/Solver.h>
|
||||
|
||||
Solver::Solver()
|
||||
: part1{ 0 }, part2{ 0 } {}
|
|
@ -1,5 +1,5 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -16,7 +16,7 @@
|
|||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
#include "SolverEngine.h"
|
||||
#include <aoc/SolverEngine.h>
|
||||
|
||||
SolverEngine::SolverEngine(const std::vector<std::string>& inputPaths)
|
||||
: inputPaths_{ inputPaths } {}
|
|
@ -1,5 +1,5 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -13,7 +13,7 @@
|
|||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "StringStateMachine.h"
|
||||
#include <aoc/StringStateMachine.h>
|
||||
|
||||
StringStateMachine::StringStateMachine(const std::string& line, StringState& entryState)
|
||||
{
|
|
@ -1,5 +1,5 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -15,10 +15,10 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "TestContext.h"
|
||||
#include <aocTests/TestContext.h>
|
||||
|
||||
class Part1TestContext :
|
||||
public TestContext
|
||||
class Part1TestContext
|
||||
: public TestContext
|
||||
{
|
||||
public:
|
||||
Part1TestContext(std::vector<std::string> inputPaths);
|
|
@ -1,5 +1,5 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -15,10 +15,10 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "TestContext.h"
|
||||
#include <aocTests/TestContext.h>
|
||||
|
||||
class Part2TestContext :
|
||||
public TestContext
|
||||
class Part2TestContext
|
||||
: public TestContext
|
||||
{
|
||||
public:
|
||||
Part2TestContext(std::vector<std::string> inputPaths);
|
|
@ -1,5 +1,5 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -18,7 +18,7 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <Solver.h>
|
||||
#include <aoc/Solver.h>
|
||||
|
||||
class TestContext
|
||||
{
|
|
@ -1,5 +1,5 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -13,8 +13,7 @@
|
|||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "pch.h"
|
||||
#include "Part1TestContext.h"
|
||||
#include <aocTests/Part1TestContext.h>
|
||||
|
||||
Part1TestContext::Part1TestContext(std::vector<std::string> inputPaths)
|
||||
: TestContext{ inputPaths } {}
|
|
@ -1,5 +1,5 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -13,8 +13,7 @@
|
|||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "pch.h"
|
||||
#include "Part2TestContext.h"
|
||||
#include <aocTests/Part2TestContext.h>
|
||||
|
||||
Part2TestContext::Part2TestContext(std::vector<std::string> inputPaths)
|
||||
: TestContext{ inputPaths } {}
|
|
@ -0,0 +1,70 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
// Foundation, either version 3 of the License, or (at your option) any later
|
||||
// version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include <aocTests/Part1TestContext.h>
|
||||
#include <aocTests/Part2TestContext.h>
|
||||
|
||||
#include <aoc/Solver.h>
|
||||
#include <aoc/SolverEngine.h>
|
||||
#include <aoc/HistorianHysteria.h>
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#define REQUIRE_MESSAGE(cond, msg) if (!(cond)) { INFO(msg); REQUIRE(cond); }
|
||||
|
||||
class HistorianHysteriaTests
|
||||
{
|
||||
public:
|
||||
Part1TestContext part1TestContext_{ getInputPaths() };
|
||||
Part2TestContext part2TestContext_{ getInputPaths() };
|
||||
Part1TestContext part1ExampleTestContext_{ getExampleInputPaths() };
|
||||
Part2TestContext part2ExampleTestContext_{ getExampleInputPaths() };
|
||||
|
||||
void runTest(Solver &solver, const long long int expected, const TestContext &context)
|
||||
{
|
||||
SolverEngine solverEngine{context.getInputPaths()};
|
||||
solverEngine.run(solver);
|
||||
|
||||
REQUIRE(expected == context.getResult(solver));
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<std::string> getInputPaths() const
|
||||
{
|
||||
return std::vector<std::string>{ "data", "../../../data", "../../../../data" };
|
||||
}
|
||||
|
||||
std::vector<std::string> getExampleInputPaths() const
|
||||
{
|
||||
return std::vector<std::string>{ "data/examples", "../../../data/examples", "../../../../data/examples" };
|
||||
}
|
||||
};
|
||||
|
||||
TEST_CASE( "[HistorianHysteriaTests]" )
|
||||
{
|
||||
HistorianHysteriaTests tests;
|
||||
SECTION( "FullData1" ) {
|
||||
tests.runTest(*std::make_unique<HistorianHysteria>(), 2176849, tests.part1TestContext_);
|
||||
}
|
||||
SECTION( "FullData2" ) {
|
||||
tests.runTest(*std::make_unique<HistorianHysteria>(), 23384288, tests.part2TestContext_);
|
||||
}
|
||||
SECTION( "ExampleData1" ) {
|
||||
tests.runTest(*std::make_unique<HistorianHysteria>(), 11, tests.part1ExampleTestContext_);
|
||||
}
|
||||
SECTION( "ExampleData2" ) {
|
||||
tests.runTest(*std::make_unique<HistorianHysteria>(), 31, tests.part2ExampleTestContext_);
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -13,8 +13,7 @@
|
|||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "pch.h"
|
||||
#include "TestContext.h"
|
||||
#include <aocTests/TestContext.h>
|
||||
|
||||
TestContext::TestContext(std::vector<std::string> inputPaths)
|
||||
: inputPaths_{ inputPaths } {}
|
Loading…
Reference in New Issue