Add proper CMake setup and update project structure

This commit is contained in:
2024-12-06 20:16:01 +01:00
parent fdfdca84e4
commit 38bca1e549
56 changed files with 282 additions and 681 deletions

View File

@@ -0,0 +1,33 @@
// 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 <set>
#include <aoc/Solver.h>
class HistorianHysteria
: public Solver
{
public:
virtual std::string getPuzzleName() const override;
virtual std::string getInputFileName() const override;
virtual void processDataLine(const std::string& line) override;
virtual void finish() override;
private:
std::multiset<int> left;
std::multiset<int> right;
};

View File

@@ -0,0 +1,33 @@
// 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 <aoc/StringState.h>
class MullCharState
: public StringState
{
public:
MullCharState(const char expected);
void enter(StringStateMachine* stateMachine) override {};
void next(StringStateMachine* stateMachine) override;
void exit(StringStateMachine* stateMachine) override {};
void setTransitions(StringState& successState, StringState& failState);
private:
char expected_;
StringState* successState_;
StringState* failState_;
};

35
include/aoc/MullData.h Normal file
View File

@@ -0,0 +1,35 @@
// 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 MullData
{
public:
MullData();
bool getIsEnabled();
void setIsEnabled(const bool value);
int getFactor(const int index);
void setFactor(const int index, const int value);
void updateResult();
long long int getResultPart1();
long long int getResultPart2();
private:
bool isEnabled_;
int factor1_;
int factor2_;
long long int part1_;
long long int part2_;
};

View File

@@ -0,0 +1,28 @@
// 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 <aoc/MullData.h>
#include <aoc/StringState.h>
class MullDataState
: public StringState
{
public:
void setData(MullData& data);
protected:
MullData* data_{ nullptr };
};

View File

@@ -0,0 +1,32 @@
// 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 <aoc/MullDataState.h>
class MullDoOpenState
: public MullDataState
{
public:
void enter(StringStateMachine* stateMachine) override {};
void next(StringStateMachine* stateMachine) override;
void exit(StringStateMachine* stateMachine) override {};
void setTransitions(StringState& doState, StringState& dontState, StringState& failState);
private:
StringState* doState_;
StringState* dontState_;
StringState* failState_;
};

View File

@@ -0,0 +1,31 @@
// 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 <aoc/StringState.h>
class MullEntryState
: public StringState
{
public:
void enter(StringStateMachine* stateMachine) override;
void next(StringStateMachine* stateMachine) override;
void exit(StringStateMachine* stateMachine) override {};
void setTransitions(StringState& mulState, StringState& doState);
private:
StringState* mulState_;
StringState* doState_;
};

View File

@@ -0,0 +1,34 @@
// 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 <aoc/MullDataState.h>
class MullFactorState
: public MullDataState
{
public:
MullFactorState(const char expected, const int index);
void enter(StringStateMachine* stateMachine) override;
void next(StringStateMachine* stateMachine) override;
void exit(StringStateMachine* stateMachine) override {};
void setTransitions(StringState& successState, StringState& failState);
private:
char expected_;
int index_;
StringState* successState_;
StringState* failState_;
};

34
include/aoc/MullItOver.h Normal file
View File

@@ -0,0 +1,34 @@
// 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 <aoc/MullData.h>
#include <aoc/MullStates.h>
#include <aoc/Solver.h>
class MullItOver
: public Solver
{
public:
MullItOver();
std::string getPuzzleName() const override;
std::string getInputFileName() const override;
void processDataLine(const std::string& line) override;
void finish() override;
private:
MullData data_;
MullStates states_;
};

41
include/aoc/MullStates.h Normal file
View File

@@ -0,0 +1,41 @@
// 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 <aoc/MullCharState.h>
#include <aoc/MullDoOpenState.h>
#include <aoc/MullEntryState.h>
#include <aoc/MullFactorState.h>
#include <aoc/MullToggleCloseState.h>
class MullStates
{
public:
MullStates(MullData& data);
MullEntryState entryState;
MullCharState uState{ 'u' };
MullCharState lState{ 'l' };
MullCharState mulOpenState{ '(' };
MullFactorState factor1State{ ',', 1 };
MullFactorState factor2State{ ')', 2 };
MullCharState oState{ 'o' };
MullDoOpenState doOpenState;
MullToggleCloseState doCloseState{ true };
MullCharState apostropheState{ '\'' };
MullCharState tState{ 't' };
MullCharState dontOpenState{ '(' };
MullToggleCloseState dontCloseState{ false };
};

View File

@@ -0,0 +1,32 @@
// 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 <aoc/MullDataState.h>
class MullToggleCloseState
: public MullDataState
{
public:
MullToggleCloseState(const bool isEnabler);
void enter(StringStateMachine* stateMachine) override {};
void next(StringStateMachine* stateMachine) override;
void exit(StringStateMachine* stateMachine) override {};
void setTransitions(StringState& successState);
private:
bool isEnabler_;
StringState* successState_;
};

28
include/aoc/Program.h Normal file
View File

@@ -0,0 +1,28 @@
// 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 <string>
#include <vector>
class Program
{
public:
void run();
private:
void runSolvers();
std::vector<std::string> getInputPaths() const;
};

View File

@@ -0,0 +1,32 @@
// 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 <aoc/Slope.h>
class RedNosedReportData
{
public:
bool isSafe{ true };
bool canUseDampener{ true };
bool mustSkipPrevious{ false };
bool mustCheckSlopeReversal{ false };
bool mustAwaitFourLevels{ false };
Slope slope{ Slope::Unknown };
std::vector<int> levels{};
};

View File

@@ -0,0 +1,33 @@
// 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 <aoc/Slope.h>
#include <aoc/Solver.h>
#include <aoc/RedNosedReportData.h>
class RedNosedReports
: public Solver
{
public:
std::string getPuzzleName() const override;
std::string getInputFileName() const override;
void processDataLine(const std::string& line) override;
void finish() override;
private:
void checkLastLevel(const Slope sameSlope, const Slope otherSlope,
const int delta, const int sign, RedNosedReportData& data);
};

18
include/aoc/Slope.h Normal file
View File

@@ -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 <http://www.gnu.org/licenses/>.
#pragma once
enum class Slope { Unknown, Increasing, Decreasing };

34
include/aoc/Solver.h Normal file
View File

@@ -0,0 +1,34 @@
// 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 <string>
class Solver
{
public:
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 finish() = 0;
long long int getResultPart1() const;
long long int getResultPart2() const;
protected:
long long int part1;
long long int part2;
};

View File

@@ -0,0 +1,34 @@
// 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 <filesystem>
#include <string>
#include <memory>
#include <vector>
#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);
};

31
include/aoc/StringState.h Normal file
View File

@@ -0,0 +1,31 @@
// 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 <aoc/StringStateMachine.h>
class StringStateMachine;
class StringState
{
public:
virtual void enter(StringStateMachine* stateMachine) = 0;
virtual void next(StringStateMachine* stateMachine) = 0;
virtual void exit(StringStateMachine* stateMachine) = 0;
virtual ~StringState() {};
};

View File

@@ -0,0 +1,36 @@
// 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 <string>
#include <aoc/StringState.h>
class StringState;
class StringStateMachine
{
public:
StringStateMachine(const std::string& line, StringState& entryState);
void run();
char getCurrent() const;
void setState(StringState& state);
private:
std::string line_;
StringState* entryState_;
StringState* currentState_;
char current_;
};