From 40101b71a46c6a7255d9212405b77ec6b52329f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20M=C3=BCller?= Date: Wed, 4 Dec 2024 19:26:04 +0100 Subject: [PATCH 1/5] Change project to CMake --- .gitignore | 1 + AdventOfCode2024/AdventOfCode2024.cpp | 10 +- AdventOfCode2024/AdventOfCode2024.h | 18 ++ AdventOfCode2024/AdventOfCode2024.sln | 41 ---- AdventOfCode2024/AdventOfCode2024.vcxproj | 178 ----------------- .../AdventOfCode2024.vcxproj.filters | 144 -------------- AdventOfCode2024/CMakeLists.txt | 21 ++ AdventOfCode2024/CMakePresets.json | 61 ++++++ AdventOfCode2024/UnitTests/UnitTests.vcxproj | 187 ------------------ .../UnitTests/UnitTests.vcxproj.filters | 48 ----- AdventOfCode2024/UnitTests/pch.cpp | 5 - AdventOfCode2024/UnitTests/pch.h | 12 -- 12 files changed, 106 insertions(+), 620 deletions(-) create mode 100644 AdventOfCode2024/AdventOfCode2024.h delete mode 100644 AdventOfCode2024/AdventOfCode2024.sln delete mode 100644 AdventOfCode2024/AdventOfCode2024.vcxproj delete mode 100644 AdventOfCode2024/AdventOfCode2024.vcxproj.filters create mode 100644 AdventOfCode2024/CMakeLists.txt create mode 100644 AdventOfCode2024/CMakePresets.json delete mode 100644 AdventOfCode2024/UnitTests/UnitTests.vcxproj delete mode 100644 AdventOfCode2024/UnitTests/UnitTests.vcxproj.filters delete mode 100644 AdventOfCode2024/UnitTests/pch.cpp delete mode 100644 AdventOfCode2024/UnitTests/pch.h diff --git a/.gitignore b/.gitignore index cad4563..5d8ffd9 100644 --- a/.gitignore +++ b/.gitignore @@ -35,4 +35,5 @@ # VS and Output .vs Debug/ +out/ *.vcxproj.user \ No newline at end of file diff --git a/AdventOfCode2024/AdventOfCode2024.cpp b/AdventOfCode2024/AdventOfCode2024.cpp index 010d4a1..d9b0ae0 100644 --- a/AdventOfCode2024/AdventOfCode2024.cpp +++ b/AdventOfCode2024/AdventOfCode2024.cpp @@ -1,6 +1,6 @@ -// Solutions to the Advent Of Code 2024. -// Copyright (C) 2024 Stefan Müller -// +// 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 @@ -13,11 +13,11 @@ // You should have received a copy of the GNU General Public License along with // this program. If not, see . -#include "Program.h" +#include "AdventOfCode2024.h" int main() { Program program; program.run(); return 0; -} \ No newline at end of file +} diff --git a/AdventOfCode2024/AdventOfCode2024.h b/AdventOfCode2024/AdventOfCode2024.h new file mode 100644 index 0000000..5fa518c --- /dev/null +++ b/AdventOfCode2024/AdventOfCode2024.h @@ -0,0 +1,18 @@ +// 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 . + +#pragma once + +#include "Program.h" diff --git a/AdventOfCode2024/AdventOfCode2024.sln b/AdventOfCode2024/AdventOfCode2024.sln deleted file mode 100644 index ff8d565..0000000 --- a/AdventOfCode2024/AdventOfCode2024.sln +++ /dev/null @@ -1,41 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.7.34221.43 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AdventOfCode2024", "AdventOfCode2024.vcxproj", "{0DEDB176-15A1-48C2-B710-5F17538C5DEC}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UnitTests", "UnitTests\UnitTests.vcxproj", "{15C7DA0D-C4D8-420B-AC10-D213AD22B9FA}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|x64 = Release|x64 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {0DEDB176-15A1-48C2-B710-5F17538C5DEC}.Debug|x64.ActiveCfg = Debug|x64 - {0DEDB176-15A1-48C2-B710-5F17538C5DEC}.Debug|x64.Build.0 = Debug|x64 - {0DEDB176-15A1-48C2-B710-5F17538C5DEC}.Debug|x86.ActiveCfg = Debug|Win32 - {0DEDB176-15A1-48C2-B710-5F17538C5DEC}.Debug|x86.Build.0 = Debug|Win32 - {0DEDB176-15A1-48C2-B710-5F17538C5DEC}.Release|x64.ActiveCfg = Release|x64 - {0DEDB176-15A1-48C2-B710-5F17538C5DEC}.Release|x64.Build.0 = Release|x64 - {0DEDB176-15A1-48C2-B710-5F17538C5DEC}.Release|x86.ActiveCfg = Release|Win32 - {0DEDB176-15A1-48C2-B710-5F17538C5DEC}.Release|x86.Build.0 = Release|Win32 - {15C7DA0D-C4D8-420B-AC10-D213AD22B9FA}.Debug|x64.ActiveCfg = Debug|x64 - {15C7DA0D-C4D8-420B-AC10-D213AD22B9FA}.Debug|x64.Build.0 = Debug|x64 - {15C7DA0D-C4D8-420B-AC10-D213AD22B9FA}.Debug|x86.ActiveCfg = Debug|Win32 - {15C7DA0D-C4D8-420B-AC10-D213AD22B9FA}.Debug|x86.Build.0 = Debug|Win32 - {15C7DA0D-C4D8-420B-AC10-D213AD22B9FA}.Release|x64.ActiveCfg = Release|x64 - {15C7DA0D-C4D8-420B-AC10-D213AD22B9FA}.Release|x64.Build.0 = Release|x64 - {15C7DA0D-C4D8-420B-AC10-D213AD22B9FA}.Release|x86.ActiveCfg = Release|Win32 - {15C7DA0D-C4D8-420B-AC10-D213AD22B9FA}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {09BCF972-2454-4BE3-9637-D49111238A7F} - EndGlobalSection -EndGlobal diff --git a/AdventOfCode2024/AdventOfCode2024.vcxproj b/AdventOfCode2024/AdventOfCode2024.vcxproj deleted file mode 100644 index 46d2eb9..0000000 --- a/AdventOfCode2024/AdventOfCode2024.vcxproj +++ /dev/null @@ -1,178 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 17.0 - Win32Proj - {0dedb176-15a1-48c2-b710-5f17538c5dec} - AdventOfCode2024 - 10.0 - - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - - - - - - - - - - - - - - - - - - - - Level3 - true - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - Level3 - true - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - Level3 - true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - stdcpp17 - - - Console - true - - - - - Level3 - true - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/AdventOfCode2024/AdventOfCode2024.vcxproj.filters b/AdventOfCode2024/AdventOfCode2024.vcxproj.filters deleted file mode 100644 index 12b5bc2..0000000 --- a/AdventOfCode2024/AdventOfCode2024.vcxproj.filters +++ /dev/null @@ -1,144 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - \ No newline at end of file diff --git a/AdventOfCode2024/CMakeLists.txt b/AdventOfCode2024/CMakeLists.txt new file mode 100644 index 0000000..0ab10db --- /dev/null +++ b/AdventOfCode2024/CMakeLists.txt @@ -0,0 +1,21 @@ +# 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 "$,$>,$<$:EditAndContinue>,$<$: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. diff --git a/AdventOfCode2024/CMakePresets.json b/AdventOfCode2024/CMakePresets.json new file mode 100644 index 0000000..abf4065 --- /dev/null +++ b/AdventOfCode2024/CMakePresets.json @@ -0,0 +1,61 @@ +{ + "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" + } + } + ] +} diff --git a/AdventOfCode2024/UnitTests/UnitTests.vcxproj b/AdventOfCode2024/UnitTests/UnitTests.vcxproj deleted file mode 100644 index c5dd3f5..0000000 --- a/AdventOfCode2024/UnitTests/UnitTests.vcxproj +++ /dev/null @@ -1,187 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 17.0 - {15C7DA0D-C4D8-420B-AC10-D213AD22B9FA} - Win32Proj - UnitTests - 10.0 - NativeUnitTestProject - - - - DynamicLibrary - true - v143 - Unicode - false - - - DynamicLibrary - false - v143 - true - Unicode - false - - - DynamicLibrary - true - v143 - Unicode - false - - - DynamicLibrary - false - v143 - true - Unicode - false - - - - - - - - - - - - - - - - - - - - - true - ..;$(IncludePath) - - - true - - - false - - - false - - - - Use - Level3 - true - $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) - _DEBUG;%(PreprocessorDefinitions) - true - pch.h - stdcpp17 - - - Windows - $(VCInstallDir)UnitTest\lib;$(SolutionDir)$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) - Solver.obj;SolverEngine.obj;HistorianHysteria.obj;RedNosedReports.obj;%(AdditionalDependencies) - - - - - Use - Level3 - true - $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;%(PreprocessorDefinitions) - true - pch.h - - - Windows - $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) - - - - - Use - Level3 - true - true - true - $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;%(PreprocessorDefinitions) - true - pch.h - - - Windows - true - true - $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) - - - - - Use - Level3 - true - true - true - $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories) - NDEBUG;%(PreprocessorDefinitions) - true - pch.h - - - Windows - true - true - $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) - - - - - - - Create - Create - Create - Create - - - - - - - - - - - - - {0dedb176-15a1-48c2-b710-5f17538c5dec} - - - - - - \ No newline at end of file diff --git a/AdventOfCode2024/UnitTests/UnitTests.vcxproj.filters b/AdventOfCode2024/UnitTests/UnitTests.vcxproj.filters deleted file mode 100644 index dc63046..0000000 --- a/AdventOfCode2024/UnitTests/UnitTests.vcxproj.filters +++ /dev/null @@ -1,48 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - \ No newline at end of file diff --git a/AdventOfCode2024/UnitTests/pch.cpp b/AdventOfCode2024/UnitTests/pch.cpp deleted file mode 100644 index 64b7eef..0000000 --- a/AdventOfCode2024/UnitTests/pch.cpp +++ /dev/null @@ -1,5 +0,0 @@ -// pch.cpp: source file corresponding to the pre-compiled header - -#include "pch.h" - -// When you are using pre-compiled headers, this source file is necessary for compilation to succeed. diff --git a/AdventOfCode2024/UnitTests/pch.h b/AdventOfCode2024/UnitTests/pch.h deleted file mode 100644 index 9d715b0..0000000 --- a/AdventOfCode2024/UnitTests/pch.h +++ /dev/null @@ -1,12 +0,0 @@ -// pch.h: This is a precompiled header file. -// Files listed below are compiled only once, improving build performance for future builds. -// This also affects IntelliSense performance, including code completion and many code browsing features. -// However, files listed here are ALL re-compiled if any one of them is updated between builds. -// Do not add files here that you will be updating frequently as this negates the performance advantage. - -#ifndef PCH_H -#define PCH_H - -// add headers that you want to pre-compile here - -#endif //PCH_H From fdfdca84e45cf33e4cadc1e309d296474c946ac5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20M=C3=BCller?= Date: Wed, 4 Dec 2024 19:55:39 +0100 Subject: [PATCH 2/5] Fix unicode chars in header comment --- AdventOfCode2024/AdventOfCode2024.cpp | 2 +- AdventOfCode2024/AdventOfCode2024.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/AdventOfCode2024/AdventOfCode2024.cpp b/AdventOfCode2024/AdventOfCode2024.cpp index d9b0ae0..86e9c38 100644 --- a/AdventOfCode2024/AdventOfCode2024.cpp +++ b/AdventOfCode2024/AdventOfCode2024.cpp @@ -1,6 +1,6 @@ // 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 diff --git a/AdventOfCode2024/AdventOfCode2024.h b/AdventOfCode2024/AdventOfCode2024.h index 5fa518c..a516c89 100644 --- a/AdventOfCode2024/AdventOfCode2024.h +++ b/AdventOfCode2024/AdventOfCode2024.h @@ -1,6 +1,6 @@ // 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 From 38bca1e549a4c021f69dbb6ef1b1c5b3e9e59211 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20M=C3=BCller?= Date: Fri, 6 Dec 2024 20:16:01 +0100 Subject: [PATCH 3/5] Add proper CMake setup and update project structure --- .gitattributes | 37 +++++++++ .gitignore | 4 +- ...ventOfCode2024.cpp => AdventOfCode2024.cpp | 4 +- AdventOfCode2024/.editorconfig | 82 ------------------- AdventOfCode2024/AdventOfCode2024.h | 18 ---- AdventOfCode2024/CMakeLists.txt | 21 ----- AdventOfCode2024/CMakePresets.json | 61 -------------- AdventOfCode2024/CeresSearch.cpp | 80 ------------------ AdventOfCode2024/CeresSearch.h | 33 -------- AdventOfCode2024/LinesSolver.cpp | 32 -------- AdventOfCode2024/LinesSolver.h | 32 -------- AdventOfCode2024/Point2.cpp | 81 ------------------ AdventOfCode2024/Point2.h | 36 -------- AdventOfCode2024/StringState.cpp | 1 - AdventOfCode2024/UnitTests/UnitTests.cpp | 82 ------------------- CMakeLists.txt | 57 +++++++++++++ .../aoc}/HistorianHysteria.h | 8 +- .../aoc}/MullCharState.h | 8 +- {AdventOfCode2024 => include/aoc}/MullData.h | 2 +- .../aoc}/MullDataState.h | 10 +-- .../aoc}/MullDoOpenState.h | 8 +- .../aoc}/MullEntryState.h | 8 +- .../aoc}/MullFactorState.h | 8 +- .../aoc}/MullItOver.h | 12 +-- .../aoc}/MullStates.h | 12 +-- .../aoc}/MullToggleCloseState.h | 8 +- {AdventOfCode2024 => include/aoc}/Program.h | 2 +- .../aoc}/RedNosedReportData.h | 4 +- .../aoc}/RedNosedReports.h | 12 +-- {AdventOfCode2024 => include/aoc}/Slope.h | 2 +- {AdventOfCode2024 => include/aoc}/Solver.h | 6 +- .../aoc}/SolverEngine.h | 5 +- .../aoc}/StringState.h | 4 +- .../aoc}/StringStateMachine.h | 4 +- .../HistorianHysteria.cpp | 4 +- {AdventOfCode2024 => src}/MullCharState.cpp | 4 +- {AdventOfCode2024 => src}/MullData.cpp | 4 +- {AdventOfCode2024 => src}/MullDataState.cpp | 4 +- {AdventOfCode2024 => src}/MullDoOpenState.cpp | 4 +- {AdventOfCode2024 => src}/MullEntryState.cpp | 4 +- {AdventOfCode2024 => src}/MullFactorState.cpp | 4 +- {AdventOfCode2024 => src}/MullItOver.cpp | 6 +- {AdventOfCode2024 => src}/MullStates.cpp | 4 +- .../MullToggleCloseState.cpp | 4 +- {AdventOfCode2024 => src}/Program.cpp | 16 ++-- {AdventOfCode2024 => src}/RedNosedReports.cpp | 4 +- {AdventOfCode2024 => src}/Solver.cpp | 4 +- {AdventOfCode2024 => src}/SolverEngine.cpp | 4 +- .../StringStateMachine.cpp | 4 +- .../include/aocTests}/Part1TestContext.h | 8 +- .../include/aocTests}/Part2TestContext.h | 8 +- .../include/aocTests}/TestContext.h | 4 +- .../src}/Part1TestContext.cpp | 5 +- .../src}/Part2TestContext.cpp | 5 +- tests/src/TestCases.cpp | 70 ++++++++++++++++ .../UnitTests => tests/src}/TestContext.cpp | 5 +- 56 files changed, 282 insertions(+), 681 deletions(-) create mode 100644 .gitattributes rename AdventOfCode2024/AdventOfCode2024.cpp => AdventOfCode2024.cpp (91%) delete mode 100644 AdventOfCode2024/.editorconfig delete mode 100644 AdventOfCode2024/AdventOfCode2024.h delete mode 100644 AdventOfCode2024/CMakeLists.txt delete mode 100644 AdventOfCode2024/CMakePresets.json delete mode 100644 AdventOfCode2024/CeresSearch.cpp delete mode 100644 AdventOfCode2024/CeresSearch.h delete mode 100644 AdventOfCode2024/LinesSolver.cpp delete mode 100644 AdventOfCode2024/LinesSolver.h delete mode 100644 AdventOfCode2024/Point2.cpp delete mode 100644 AdventOfCode2024/Point2.h delete mode 100644 AdventOfCode2024/StringState.cpp delete mode 100644 AdventOfCode2024/UnitTests/UnitTests.cpp create mode 100644 CMakeLists.txt rename {AdventOfCode2024 => include/aoc}/HistorianHysteria.h (90%) rename {AdventOfCode2024 => include/aoc}/MullCharState.h (90%) rename {AdventOfCode2024 => include/aoc}/MullData.h (96%) rename {AdventOfCode2024 => include/aoc}/MullDataState.h (85%) rename {AdventOfCode2024 => include/aoc}/MullDoOpenState.h (90%) rename {AdventOfCode2024 => include/aoc}/MullEntryState.h (90%) rename {AdventOfCode2024 => include/aoc}/MullFactorState.h (90%) rename {AdventOfCode2024 => include/aoc}/MullItOver.h (86%) rename {AdventOfCode2024 => include/aoc}/MullStates.h (86%) rename {AdventOfCode2024 => include/aoc}/MullToggleCloseState.h (89%) rename {AdventOfCode2024 => include/aoc}/Program.h (95%) rename {AdventOfCode2024 => include/aoc}/RedNosedReportData.h (94%) rename {AdventOfCode2024 => include/aoc}/RedNosedReports.h (86%) rename {AdventOfCode2024 => include/aoc}/Slope.h (95%) rename {AdventOfCode2024 => include/aoc}/Solver.h (89%) rename {AdventOfCode2024 => include/aoc}/SolverEngine.h (94%) rename {AdventOfCode2024 => include/aoc}/StringState.h (93%) rename {AdventOfCode2024 => include/aoc}/StringStateMachine.h (94%) rename {AdventOfCode2024 => src}/HistorianHysteria.cpp (96%) rename {AdventOfCode2024 => src}/MullCharState.cpp (94%) rename {AdventOfCode2024 => src}/MullData.cpp (95%) rename {AdventOfCode2024 => src}/MullDataState.cpp (91%) rename {AdventOfCode2024 => src}/MullDoOpenState.cpp (94%) rename {AdventOfCode2024 => src}/MullEntryState.cpp (94%) rename {AdventOfCode2024 => src}/MullFactorState.cpp (96%) rename {AdventOfCode2024 => src}/MullItOver.cpp (92%) rename {AdventOfCode2024 => src}/MullStates.cpp (96%) rename {AdventOfCode2024 => src}/MullToggleCloseState.cpp (93%) rename {AdventOfCode2024 => src}/Program.cpp (79%) rename {AdventOfCode2024 => src}/RedNosedReports.cpp (98%) rename {AdventOfCode2024 => src}/Solver.cpp (93%) rename {AdventOfCode2024 => src}/SolverEngine.cpp (97%) rename {AdventOfCode2024 => src}/StringStateMachine.cpp (94%) rename {AdventOfCode2024/UnitTests => tests/include/aocTests}/Part1TestContext.h (87%) rename {AdventOfCode2024/UnitTests => tests/include/aocTests}/Part2TestContext.h (87%) rename {AdventOfCode2024/UnitTests => tests/include/aocTests}/TestContext.h (94%) rename {AdventOfCode2024/UnitTests => tests/src}/Part1TestContext.cpp (91%) rename {AdventOfCode2024/UnitTests => tests/src}/Part2TestContext.cpp (91%) create mode 100644 tests/src/TestCases.cpp rename {AdventOfCode2024/UnitTests => tests/src}/TestContext.cpp (91%) diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..c4e98c0 --- /dev/null +++ b/.gitattributes @@ -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 diff --git a/.gitignore b/.gitignore index 5d8ffd9..f28f810 100644 --- a/.gitignore +++ b/.gitignore @@ -35,5 +35,5 @@ # VS and Output .vs Debug/ -out/ -*.vcxproj.user \ No newline at end of file +*.vcxproj.user +build/ \ No newline at end of file diff --git a/AdventOfCode2024/AdventOfCode2024.cpp b/AdventOfCode2024.cpp similarity index 91% rename from AdventOfCode2024/AdventOfCode2024.cpp rename to AdventOfCode2024.cpp index 86e9c38..3600603 100644 --- a/AdventOfCode2024/AdventOfCode2024.cpp +++ b/AdventOfCode2024.cpp @@ -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 . -#include "AdventOfCode2024.h" +#include int main() { diff --git a/AdventOfCode2024/.editorconfig b/AdventOfCode2024/.editorconfig deleted file mode 100644 index c031793..0000000 --- a/AdventOfCode2024/.editorconfig +++ /dev/null @@ -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 diff --git a/AdventOfCode2024/AdventOfCode2024.h b/AdventOfCode2024/AdventOfCode2024.h deleted file mode 100644 index a516c89..0000000 --- a/AdventOfCode2024/AdventOfCode2024.h +++ /dev/null @@ -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 . - -#pragma once - -#include "Program.h" diff --git a/AdventOfCode2024/CMakeLists.txt b/AdventOfCode2024/CMakeLists.txt deleted file mode 100644 index 0ab10db..0000000 --- a/AdventOfCode2024/CMakeLists.txt +++ /dev/null @@ -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 "$,$>,$<$:EditAndContinue>,$<$: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. diff --git a/AdventOfCode2024/CMakePresets.json b/AdventOfCode2024/CMakePresets.json deleted file mode 100644 index abf4065..0000000 --- a/AdventOfCode2024/CMakePresets.json +++ /dev/null @@ -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" - } - } - ] -} diff --git a/AdventOfCode2024/CeresSearch.cpp b/AdventOfCode2024/CeresSearch.cpp deleted file mode 100644 index 538dc12..0000000 --- a/AdventOfCode2024/CeresSearch.cpp +++ /dev/null @@ -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 . - -#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++; - } -} diff --git a/AdventOfCode2024/CeresSearch.h b/AdventOfCode2024/CeresSearch.h deleted file mode 100644 index 568df15..0000000 --- a/AdventOfCode2024/CeresSearch.h +++ /dev/null @@ -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 . - -#pragma once - -#include - -#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); -}; diff --git a/AdventOfCode2024/LinesSolver.cpp b/AdventOfCode2024/LinesSolver.cpp deleted file mode 100644 index f6b68ee..0000000 --- a/AdventOfCode2024/LinesSolver.cpp +++ /dev/null @@ -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 . - -#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]; -} diff --git a/AdventOfCode2024/LinesSolver.h b/AdventOfCode2024/LinesSolver.h deleted file mode 100644 index 9a2d8bb..0000000 --- a/AdventOfCode2024/LinesSolver.h +++ /dev/null @@ -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 . - -#pragma once - -#include - -#include "Solver.h" -#include "Point2.h" - -class LinesSolver : - public Solver -{ -public: - void processDataLine(const std::string& line) override; -protected: - std::vector lines{}; - bool isInBounds(const Point2& point); - char getPosition(const Point2& point); -}; diff --git a/AdventOfCode2024/Point2.cpp b/AdventOfCode2024/Point2.cpp deleted file mode 100644 index c8843ed..0000000 --- a/AdventOfCode2024/Point2.cpp +++ /dev/null @@ -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 . - -#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 }; diff --git a/AdventOfCode2024/Point2.h b/AdventOfCode2024/Point2.h deleted file mode 100644 index ef32241..0000000 --- a/AdventOfCode2024/Point2.h +++ /dev/null @@ -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 . - -#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]; -}; diff --git a/AdventOfCode2024/StringState.cpp b/AdventOfCode2024/StringState.cpp deleted file mode 100644 index 8c5d227..0000000 --- a/AdventOfCode2024/StringState.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "StringState.h" diff --git a/AdventOfCode2024/UnitTests/UnitTests.cpp b/AdventOfCode2024/UnitTests/UnitTests.cpp deleted file mode 100644 index d65336a..0000000 --- a/AdventOfCode2024/UnitTests/UnitTests.cpp +++ /dev/null @@ -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 . - -#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(), 2176849, part1TestContext_); - } - - TEST_METHOD(FullData2) - { - runTest(*std::make_unique(), 23384288, part2TestContext_); - } - - TEST_METHOD(ExampleData1) - { - runTest(*std::make_unique(), 11, part1ExampleTestContext_); - } - - TEST_METHOD(ExampleData2) - { - runTest(*std::make_unique(), 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 getInputPaths() const - { - return std::vector{ "../../data", "../../../../data" }; - } - - std::vector getExampleInputPaths() const - { - return std::vector{ "../../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()); - } - }; -} diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..0b8e7ae --- /dev/null +++ b/CMakeLists.txt @@ -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 +) diff --git a/AdventOfCode2024/HistorianHysteria.h b/include/aoc/HistorianHysteria.h similarity index 90% rename from AdventOfCode2024/HistorianHysteria.h rename to include/aoc/HistorianHysteria.h index 218743e..5c17e9a 100644 --- a/AdventOfCode2024/HistorianHysteria.h +++ b/include/aoc/HistorianHysteria.h @@ -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 -#include "Solver.h" +#include -class HistorianHysteria : - public Solver +class HistorianHysteria + : public Solver { public: virtual std::string getPuzzleName() const override; diff --git a/AdventOfCode2024/MullCharState.h b/include/aoc/MullCharState.h similarity index 90% rename from AdventOfCode2024/MullCharState.h rename to include/aoc/MullCharState.h index 47372e2..9e30ca6 100644 --- a/AdventOfCode2024/MullCharState.h +++ b/include/aoc/MullCharState.h @@ -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 -class MullCharState : - public StringState +class MullCharState + : public StringState { public: MullCharState(const char expected); diff --git a/AdventOfCode2024/MullData.h b/include/aoc/MullData.h similarity index 96% rename from AdventOfCode2024/MullData.h rename to include/aoc/MullData.h index 0931b0b..4cdad06 100644 --- a/AdventOfCode2024/MullData.h +++ b/include/aoc/MullData.h @@ -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 diff --git a/AdventOfCode2024/MullDataState.h b/include/aoc/MullDataState.h similarity index 85% rename from AdventOfCode2024/MullDataState.h rename to include/aoc/MullDataState.h index 2b014e9..7b6d782 100644 --- a/AdventOfCode2024/MullDataState.h +++ b/include/aoc/MullDataState.h @@ -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 +#include -class MullDataState : - public StringState +class MullDataState + : public StringState { public: void setData(MullData& data); diff --git a/AdventOfCode2024/MullDoOpenState.h b/include/aoc/MullDoOpenState.h similarity index 90% rename from AdventOfCode2024/MullDoOpenState.h rename to include/aoc/MullDoOpenState.h index c07dc33..e4d448b 100644 --- a/AdventOfCode2024/MullDoOpenState.h +++ b/include/aoc/MullDoOpenState.h @@ -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 -class MullDoOpenState : - public MullDataState +class MullDoOpenState + : public MullDataState { public: void enter(StringStateMachine* stateMachine) override {}; diff --git a/AdventOfCode2024/MullEntryState.h b/include/aoc/MullEntryState.h similarity index 90% rename from AdventOfCode2024/MullEntryState.h rename to include/aoc/MullEntryState.h index 9e505cc..f6382d4 100644 --- a/AdventOfCode2024/MullEntryState.h +++ b/include/aoc/MullEntryState.h @@ -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 -class MullEntryState : - public StringState +class MullEntryState + : public StringState { public: void enter(StringStateMachine* stateMachine) override; diff --git a/AdventOfCode2024/MullFactorState.h b/include/aoc/MullFactorState.h similarity index 90% rename from AdventOfCode2024/MullFactorState.h rename to include/aoc/MullFactorState.h index e30c9d1..790fb99 100644 --- a/AdventOfCode2024/MullFactorState.h +++ b/include/aoc/MullFactorState.h @@ -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 -class MullFactorState : - public MullDataState +class MullFactorState + : public MullDataState { public: MullFactorState(const char expected, const int index); diff --git a/AdventOfCode2024/MullItOver.h b/include/aoc/MullItOver.h similarity index 86% rename from AdventOfCode2024/MullItOver.h rename to include/aoc/MullItOver.h index fff410a..9ef289e 100644 --- a/AdventOfCode2024/MullItOver.h +++ b/include/aoc/MullItOver.h @@ -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 +#include +#include -class MullItOver : - public Solver +class MullItOver + : public Solver { public: MullItOver(); diff --git a/AdventOfCode2024/MullStates.h b/include/aoc/MullStates.h similarity index 86% rename from AdventOfCode2024/MullStates.h rename to include/aoc/MullStates.h index 952ebe1..5c3c26e 100644 --- a/AdventOfCode2024/MullStates.h +++ b/include/aoc/MullStates.h @@ -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 +#include +#include +#include +#include class MullStates { diff --git a/AdventOfCode2024/MullToggleCloseState.h b/include/aoc/MullToggleCloseState.h similarity index 89% rename from AdventOfCode2024/MullToggleCloseState.h rename to include/aoc/MullToggleCloseState.h index 76f0615..401c5b3 100644 --- a/AdventOfCode2024/MullToggleCloseState.h +++ b/include/aoc/MullToggleCloseState.h @@ -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 -class MullToggleCloseState : - public MullDataState +class MullToggleCloseState + : public MullDataState { public: MullToggleCloseState(const bool isEnabler); diff --git a/AdventOfCode2024/Program.h b/include/aoc/Program.h similarity index 95% rename from AdventOfCode2024/Program.h rename to include/aoc/Program.h index 0d969f7..cd3708f 100644 --- a/AdventOfCode2024/Program.h +++ b/include/aoc/Program.h @@ -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 diff --git a/AdventOfCode2024/RedNosedReportData.h b/include/aoc/RedNosedReportData.h similarity index 94% rename from AdventOfCode2024/RedNosedReportData.h rename to include/aoc/RedNosedReportData.h index 1da4240..3a6cffc 100644 --- a/AdventOfCode2024/RedNosedReportData.h +++ b/include/aoc/RedNosedReportData.h @@ -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 -#include "Slope.h" +#include class RedNosedReportData { diff --git a/AdventOfCode2024/RedNosedReports.h b/include/aoc/RedNosedReports.h similarity index 86% rename from AdventOfCode2024/RedNosedReports.h rename to include/aoc/RedNosedReports.h index 3386c7f..b1f1763 100644 --- a/AdventOfCode2024/RedNosedReports.h +++ b/include/aoc/RedNosedReports.h @@ -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 +#include +#include -class RedNosedReports : - public Solver +class RedNosedReports + : public Solver { public: std::string getPuzzleName() const override; diff --git a/AdventOfCode2024/Slope.h b/include/aoc/Slope.h similarity index 95% rename from AdventOfCode2024/Slope.h rename to include/aoc/Slope.h index 3aef8e4..045a042 100644 --- a/AdventOfCode2024/Slope.h +++ b/include/aoc/Slope.h @@ -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 diff --git a/AdventOfCode2024/Solver.h b/include/aoc/Solver.h similarity index 89% rename from AdventOfCode2024/Solver.h rename to include/aoc/Solver.h index 9e7254c..78dc3d6 100644 --- a/AdventOfCode2024/Solver.h +++ b/include/aoc/Solver.h @@ -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; diff --git a/AdventOfCode2024/SolverEngine.h b/include/aoc/SolverEngine.h similarity index 94% rename from AdventOfCode2024/SolverEngine.h rename to include/aoc/SolverEngine.h index b3a1eaf..ffd751b 100644 --- a/AdventOfCode2024/SolverEngine.h +++ b/include/aoc/SolverEngine.h @@ -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 #include -#include "Solver.h" +#include class SolverEngine { public: SolverEngine(const std::vector& inputPaths); void run(Solver& solver); + private: std::vector inputPaths_; std::filesystem::path tryGetValidFullInputFilePath(const std::string& inputFileName); diff --git a/AdventOfCode2024/StringState.h b/include/aoc/StringState.h similarity index 93% rename from AdventOfCode2024/StringState.h rename to include/aoc/StringState.h index 4c88cd3..2f0c9cc 100644 --- a/AdventOfCode2024/StringState.h +++ b/include/aoc/StringState.h @@ -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 -#include "StringStateMachine.h" +#include class StringStateMachine; diff --git a/AdventOfCode2024/StringStateMachine.h b/include/aoc/StringStateMachine.h similarity index 94% rename from AdventOfCode2024/StringStateMachine.h rename to include/aoc/StringStateMachine.h index b3ddfdd..1324fc0 100644 --- a/AdventOfCode2024/StringStateMachine.h +++ b/include/aoc/StringStateMachine.h @@ -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 -#include "StringState.h" +#include class StringState; diff --git a/AdventOfCode2024/HistorianHysteria.cpp b/src/HistorianHysteria.cpp similarity index 96% rename from AdventOfCode2024/HistorianHysteria.cpp rename to src/HistorianHysteria.cpp index babad2f..a491228 100644 --- a/AdventOfCode2024/HistorianHysteria.cpp +++ b/src/HistorianHysteria.cpp @@ -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 -#include "HistorianHysteria.h" +#include std::string HistorianHysteria::getPuzzleName() const { diff --git a/AdventOfCode2024/MullCharState.cpp b/src/MullCharState.cpp similarity index 94% rename from AdventOfCode2024/MullCharState.cpp rename to src/MullCharState.cpp index b1fa759..9bc86af 100644 --- a/AdventOfCode2024/MullCharState.cpp +++ b/src/MullCharState.cpp @@ -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 . -#include "MullCharState.h" +#include MullCharState::MullCharState(const char expected) : expected_{ expected }, successState_{}, failState_{} {} diff --git a/AdventOfCode2024/MullData.cpp b/src/MullData.cpp similarity index 95% rename from AdventOfCode2024/MullData.cpp rename to src/MullData.cpp index f5ac367..de04f94 100644 --- a/AdventOfCode2024/MullData.cpp +++ b/src/MullData.cpp @@ -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 . -#include "MullData.h" +#include MullData::MullData() : isEnabled_{ true }, factor1_{ 0 }, factor2_{ 0 }, part1_{ 0 }, part2_{ 0 } {}; diff --git a/AdventOfCode2024/MullDataState.cpp b/src/MullDataState.cpp similarity index 91% rename from AdventOfCode2024/MullDataState.cpp rename to src/MullDataState.cpp index 57a9ca7..488d789 100644 --- a/AdventOfCode2024/MullDataState.cpp +++ b/src/MullDataState.cpp @@ -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 . -#include "MullDataState.h" +#include void MullDataState::setData(MullData& data) { diff --git a/AdventOfCode2024/MullDoOpenState.cpp b/src/MullDoOpenState.cpp similarity index 94% rename from AdventOfCode2024/MullDoOpenState.cpp rename to src/MullDoOpenState.cpp index 048b759..8c12477 100644 --- a/AdventOfCode2024/MullDoOpenState.cpp +++ b/src/MullDoOpenState.cpp @@ -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 . -#include "MullDoOpenState.h" +#include void MullDoOpenState::next(StringStateMachine* stateMachine) { diff --git a/AdventOfCode2024/MullEntryState.cpp b/src/MullEntryState.cpp similarity index 94% rename from AdventOfCode2024/MullEntryState.cpp rename to src/MullEntryState.cpp index 5d22315..3d42946 100644 --- a/AdventOfCode2024/MullEntryState.cpp +++ b/src/MullEntryState.cpp @@ -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 . -#include "MullEntryState.h" +#include void MullEntryState::enter(StringStateMachine* stateMachine) { diff --git a/AdventOfCode2024/MullFactorState.cpp b/src/MullFactorState.cpp similarity index 96% rename from AdventOfCode2024/MullFactorState.cpp rename to src/MullFactorState.cpp index 3725049..5d63478 100644 --- a/AdventOfCode2024/MullFactorState.cpp +++ b/src/MullFactorState.cpp @@ -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 . -#include "MullFactorState.h" +#include MullFactorState::MullFactorState(const char expected, const int index) : expected_{ expected }, index_{ index }, successState_{}, failState_{} {} diff --git a/AdventOfCode2024/MullItOver.cpp b/src/MullItOver.cpp similarity index 92% rename from AdventOfCode2024/MullItOver.cpp rename to src/MullItOver.cpp index a269aa8..a71cb83 100644 --- a/AdventOfCode2024/MullItOver.cpp +++ b/src/MullItOver.cpp @@ -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 . -#include "MullItOver.h" -#include "StringStateMachine.h" +#include +#include MullItOver::MullItOver() : Solver{}, data_{}, states_ { diff --git a/AdventOfCode2024/MullStates.cpp b/src/MullStates.cpp similarity index 96% rename from AdventOfCode2024/MullStates.cpp rename to src/MullStates.cpp index 4d81379..180c09f 100644 --- a/AdventOfCode2024/MullStates.cpp +++ b/src/MullStates.cpp @@ -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 . -#include "MullStates.h" +#include MullStates::MullStates(MullData& data) { diff --git a/AdventOfCode2024/MullToggleCloseState.cpp b/src/MullToggleCloseState.cpp similarity index 93% rename from AdventOfCode2024/MullToggleCloseState.cpp rename to src/MullToggleCloseState.cpp index 5084c47..404814b 100644 --- a/AdventOfCode2024/MullToggleCloseState.cpp +++ b/src/MullToggleCloseState.cpp @@ -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 . -#include "MullToggleCloseState.h" +#include MullToggleCloseState::MullToggleCloseState(const bool isEnabler) : isEnabler_{ isEnabler }, successState_{} {} diff --git a/AdventOfCode2024/Program.cpp b/src/Program.cpp similarity index 79% rename from AdventOfCode2024/Program.cpp rename to src/Program.cpp index a36ee63..71225cc 100644 --- a/AdventOfCode2024/Program.cpp +++ b/src/Program.cpp @@ -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 #include -#include "Program.h" -#include "SolverEngine.h" +#include +#include // Solver implementations in day order. -#include "HistorianHysteria.h" -#include "RedNosedReports.h" -#include "MullItOver.h" -#include "CeresSearch.h" +#include +#include +#include void Program::run() { @@ -37,10 +36,9 @@ void Program::runSolvers() solverEngine.run(*std::make_unique()); solverEngine.run(*std::make_unique()); solverEngine.run(*std::make_unique()); - solverEngine.run(*std::make_unique()); } std::vector Program::getInputPaths() const { - return std::vector{ "data", "../../data" }; + return std::vector{ "data", "../../../data", "../../../../data" }; } diff --git a/AdventOfCode2024/RedNosedReports.cpp b/src/RedNosedReports.cpp similarity index 98% rename from AdventOfCode2024/RedNosedReports.cpp rename to src/RedNosedReports.cpp index 157f082..b71cb08 100644 --- a/AdventOfCode2024/RedNosedReports.cpp +++ b/src/RedNosedReports.cpp @@ -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 #include -#include "RedNosedReports.h" +#include std::string RedNosedReports::getPuzzleName() const { diff --git a/AdventOfCode2024/Solver.cpp b/src/Solver.cpp similarity index 93% rename from AdventOfCode2024/Solver.cpp rename to src/Solver.cpp index b788f5e..96f361e 100644 --- a/AdventOfCode2024/Solver.cpp +++ b/src/Solver.cpp @@ -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 . -#include "Solver.h" +#include Solver::Solver() : part1{ 0 }, part2{ 0 } {} diff --git a/AdventOfCode2024/SolverEngine.cpp b/src/SolverEngine.cpp similarity index 97% rename from AdventOfCode2024/SolverEngine.cpp rename to src/SolverEngine.cpp index 72314d8..da30b26 100644 --- a/AdventOfCode2024/SolverEngine.cpp +++ b/src/SolverEngine.cpp @@ -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 #include -#include "SolverEngine.h" +#include SolverEngine::SolverEngine(const std::vector& inputPaths) : inputPaths_{ inputPaths } {} diff --git a/AdventOfCode2024/StringStateMachine.cpp b/src/StringStateMachine.cpp similarity index 94% rename from AdventOfCode2024/StringStateMachine.cpp rename to src/StringStateMachine.cpp index 4235df4..9db2dee 100644 --- a/AdventOfCode2024/StringStateMachine.cpp +++ b/src/StringStateMachine.cpp @@ -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 . -#include "StringStateMachine.h" +#include StringStateMachine::StringStateMachine(const std::string& line, StringState& entryState) { diff --git a/AdventOfCode2024/UnitTests/Part1TestContext.h b/tests/include/aocTests/Part1TestContext.h similarity index 87% rename from AdventOfCode2024/UnitTests/Part1TestContext.h rename to tests/include/aocTests/Part1TestContext.h index a10f634..a3de57e 100644 --- a/AdventOfCode2024/UnitTests/Part1TestContext.h +++ b/tests/include/aocTests/Part1TestContext.h @@ -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 -class Part1TestContext : - public TestContext +class Part1TestContext + : public TestContext { public: Part1TestContext(std::vector inputPaths); diff --git a/AdventOfCode2024/UnitTests/Part2TestContext.h b/tests/include/aocTests/Part2TestContext.h similarity index 87% rename from AdventOfCode2024/UnitTests/Part2TestContext.h rename to tests/include/aocTests/Part2TestContext.h index d157fbe..a7bf364 100644 --- a/AdventOfCode2024/UnitTests/Part2TestContext.h +++ b/tests/include/aocTests/Part2TestContext.h @@ -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 -class Part2TestContext : - public TestContext +class Part2TestContext + : public TestContext { public: Part2TestContext(std::vector inputPaths); diff --git a/AdventOfCode2024/UnitTests/TestContext.h b/tests/include/aocTests/TestContext.h similarity index 94% rename from AdventOfCode2024/UnitTests/TestContext.h rename to tests/include/aocTests/TestContext.h index d8255cb..a515dd7 100644 --- a/AdventOfCode2024/UnitTests/TestContext.h +++ b/tests/include/aocTests/TestContext.h @@ -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 #include -#include +#include class TestContext { diff --git a/AdventOfCode2024/UnitTests/Part1TestContext.cpp b/tests/src/Part1TestContext.cpp similarity index 91% rename from AdventOfCode2024/UnitTests/Part1TestContext.cpp rename to tests/src/Part1TestContext.cpp index 7601f3c..8739144 100644 --- a/AdventOfCode2024/UnitTests/Part1TestContext.cpp +++ b/tests/src/Part1TestContext.cpp @@ -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 . -#include "pch.h" -#include "Part1TestContext.h" +#include Part1TestContext::Part1TestContext(std::vector inputPaths) : TestContext{ inputPaths } {} diff --git a/AdventOfCode2024/UnitTests/Part2TestContext.cpp b/tests/src/Part2TestContext.cpp similarity index 91% rename from AdventOfCode2024/UnitTests/Part2TestContext.cpp rename to tests/src/Part2TestContext.cpp index a3b3b63..455dab4 100644 --- a/AdventOfCode2024/UnitTests/Part2TestContext.cpp +++ b/tests/src/Part2TestContext.cpp @@ -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 . -#include "pch.h" -#include "Part2TestContext.h" +#include Part2TestContext::Part2TestContext(std::vector inputPaths) : TestContext{ inputPaths } {} diff --git a/tests/src/TestCases.cpp b/tests/src/TestCases.cpp new file mode 100644 index 0000000..4debf88 --- /dev/null +++ b/tests/src/TestCases.cpp @@ -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 . + +#include +#include + +#include +#include +#include + +#include + +#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 getInputPaths() const + { + return std::vector{ "data", "../../../data", "../../../../data" }; + } + + std::vector getExampleInputPaths() const + { + return std::vector{ "data/examples", "../../../data/examples", "../../../../data/examples" }; + } +}; + +TEST_CASE( "[HistorianHysteriaTests]" ) +{ + HistorianHysteriaTests tests; + SECTION( "FullData1" ) { + tests.runTest(*std::make_unique(), 2176849, tests.part1TestContext_); + } + SECTION( "FullData2" ) { + tests.runTest(*std::make_unique(), 23384288, tests.part2TestContext_); + } + SECTION( "ExampleData1" ) { + tests.runTest(*std::make_unique(), 11, tests.part1ExampleTestContext_); + } + SECTION( "ExampleData2" ) { + tests.runTest(*std::make_unique(), 31, tests.part2ExampleTestContext_); + } +} diff --git a/AdventOfCode2024/UnitTests/TestContext.cpp b/tests/src/TestContext.cpp similarity index 91% rename from AdventOfCode2024/UnitTests/TestContext.cpp rename to tests/src/TestContext.cpp index 3abd629..0d89ae6 100644 --- a/AdventOfCode2024/UnitTests/TestContext.cpp +++ b/tests/src/TestContext.cpp @@ -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 . -#include "pch.h" -#include "TestContext.h" +#include TestContext::TestContext(std::vector inputPaths) : inputPaths_{ inputPaths } {} From e6664bc6c63dab2865cb42bc5bfd5b40ba6d7f9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20M=C3=BCller?= Date: Fri, 6 Dec 2024 20:18:38 +0100 Subject: [PATCH 4/5] Update readme for CMake --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c6fe225..42c295a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Solver for Advent of Code 2024 puzzles. -This is a single command line application for the puzzles written in [C++17](https://en.cppreference.com/w/cpp/17) with [Visual Studio 2022](https://visualstudio.microsoft.com/vs/) (v143). +This is a single command line application for the puzzles written in [C++23](https://en.cppreference.com/w/cpp/23) with CMake. ## Puzzle Input @@ -38,6 +38,10 @@ A simple [finite state machine](AdventOfCode2024/StringStateMachine.h) crawling For this puzzle I added a class for [points in two-dimensional space](AdventOfCode2024/Point2.h), so I can use these for simplifying directional computations. With that, the algorithm looks for all `X` and `A` for part 1 and 2, respectively, and tries to find the remaining characters, starting from that `X` or `A`. +## Thanks + +* [Alexander Brouwer](https://github.com/Bromvlieg) for getting the project set up with CMake. + ## License Copyright (C) 2024 Stefan Müller From 5a66669ed8b26ed6730444e3b577ead2b1f97156 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20M=C3=BCller?= Date: Fri, 6 Dec 2024 22:34:13 +0100 Subject: [PATCH 5/5] Add clang format and tidy configs --- .clang-format | 31 +++++++++++++++++++++++++++++++ .clang-tidy | 30 ++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 .clang-format create mode 100644 .clang-tidy diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..afa59c0 --- /dev/null +++ b/.clang-format @@ -0,0 +1,31 @@ +# https://clang.llvm.org/docs/ClangFormatStyleOptions.html +Language: Cpp +BasedOnStyle: LLVM +AccessModifierOffset: -4 +BreakBeforeBraces: Allman +BreakBeforeTernaryOperators: true +ColumnLimit: 100 +EmptyLineBeforeAccessModifier: Never +FixNamespaceComments: false +IncludeBlocks: Regroup +IncludeCategories: + - Regex: "^<[a-z]*>" + Priority: 1 + - Regex: "^<.*/.*>" + Priority: 2 + - Regex: '^<.*\.hpp>' + Priority: 3 + - Regex: '^<.*\.h>' + Priority: 4 + - Regex: ".*" + Priority: 5 +IndentCaseLabels: true +IndentPPDirectives: BeforeHash +IndentWidth: 4 +InsertNewlineAtEOF: true +NamespaceIndentation: All +PointerAlignment: Left +ReferenceAlignment: Left +SortIncludes: CaseInsensitive +SpaceBeforeCaseColon: true +SpaceBeforeParens: ControlStatements diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..3927b91 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,30 @@ +--- +# Enable all by default, then disable some that have either too many warnings +# at the moment or ones that don't make sense for our codebase +Checks: clang-diagnostic-* + clang-analyzer-* + cppcoreguidelines-* + modernize-* + hicpp-* + -hicpp-special-member-functions + -modernize-pass-by-value + -cppcoreguidelines-pro-bounds-constant-array-index + -modernize-use-trailing-return-type + -cppcoreguidelines-avoid-non-const-global-variables + -hicpp-signed-bitwise + -hicpp-vararg + -hicpp-braces-around-statements + -hicpp-no-array-decay + -cppcoreguidelines-pro-bounds-pointer-arithmetic + -cppcoreguidelines-non-private-member-variables-in-classes + -cppcoreguidelines-avoid-magic-numbers + -cppcoreguidelines-pro-type-vararg + -modernize-avoid-c-arrays + -cppcoreguidelines-avoid-c-arrays + -cppcoreguidelines-pro-bounds-array-to-pointer-decay + -cppcoreguidelines-narrowing-conversions + -clang-analyzer-deadcode.DeadStores +WarningsAsErrors: '*' +HeaderFilterRegex: '' +AnalyzeTemporaryDtors: false +...