Change Solver into template class to allow for non-integer results
This commit is contained in:
parent
26dfb379a2
commit
7ad1b01879
@ -17,10 +17,10 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <aoc/framework/Solver.hpp>
|
#include <aoc/framework/Solver-types.hpp>
|
||||||
|
|
||||||
class BridgeRepair
|
class BridgeRepair
|
||||||
: public Solver
|
: public Solver<long long, long long>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual const std::string getPuzzleName() const override;
|
virtual const std::string getPuzzleName() const override;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Solutions to the Advent Of Code 2024.
|
// Solutions to the Advent Of Code 2024.
|
||||||
// Copyright (C) 2024 Stefan Müller
|
// Copyright (C) 2024-2025 Stefan Müller
|
||||||
//
|
//
|
||||||
// This program is free software: you can redistribute it and/or modify it under
|
// 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
|
// the terms of the GNU General Public License as published by the Free Software
|
||||||
@ -17,10 +17,10 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <aoc/framework/LinesSolver.hpp>
|
#include <aoc/framework/LinesSolver-types.hpp>
|
||||||
|
|
||||||
class CeresSearch
|
class CeresSearch
|
||||||
: public LinesSolver
|
: public LinesSolver<long long, long long>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual const std::string getPuzzleName() const override;
|
virtual const std::string getPuzzleName() const override;
|
||||||
|
@ -16,10 +16,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <aoc/common/Point2.hpp>
|
#include <aoc/common/Point2.hpp>
|
||||||
#include <aoc/framework/Solver.hpp>
|
#include <aoc/framework/Solver-types.hpp>
|
||||||
|
|
||||||
class ClawContraption
|
class ClawContraption
|
||||||
: public Solver
|
: public Solver<long long, long long>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual const std::string getPuzzleName() const override;
|
virtual const std::string getPuzzleName() const override;
|
||||||
|
@ -19,10 +19,10 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <aoc/common/Interval.hpp>
|
#include <aoc/common/Interval.hpp>
|
||||||
#include <aoc/framework/Solver.hpp>
|
#include <aoc/framework/Solver-types.hpp>
|
||||||
|
|
||||||
class DiskFragmenter
|
class DiskFragmenter
|
||||||
: public Solver
|
: public Solver<long long, long long>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual const std::string getPuzzleName() const override;
|
virtual const std::string getPuzzleName() const override;
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
#include <aoc/framework/LinesSolver.hpp>
|
#include <aoc/framework/LinesSolver.hpp>
|
||||||
|
|
||||||
class GardenGroups
|
class GardenGroups
|
||||||
: public LinesSolver
|
: public LinesSolver<long long, long long>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GardenGroups(const int inputFileNameSuffix = 0);
|
GardenGroups(const int inputFileNameSuffix = 0);
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
#include <aoc/framework/LinesSolver.hpp>
|
#include <aoc/framework/LinesSolver.hpp>
|
||||||
|
|
||||||
class GuardGallivant
|
class GuardGallivant
|
||||||
: public LinesSolver
|
: public LinesSolver<long long, long long>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual const std::string getPuzzleName() const override;
|
virtual const std::string getPuzzleName() const override;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Solutions to the Advent Of Code 2024.
|
// Solutions to the Advent Of Code 2024.
|
||||||
// Copyright (C) 2024 Stefan Müller
|
// Copyright (C) 2024-2025 Stefan Müller
|
||||||
//
|
//
|
||||||
// This program is free software: you can redistribute it and/or modify it under
|
// 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
|
// the terms of the GNU General Public License as published by the Free Software
|
||||||
@ -17,10 +17,10 @@
|
|||||||
|
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
#include <aoc/framework/Solver.hpp>
|
#include <aoc/framework/Solver-types.hpp>
|
||||||
|
|
||||||
class HistorianHysteria
|
class HistorianHysteria
|
||||||
: public Solver
|
: public Solver<long long, long long>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual const std::string getPuzzleName() const override;
|
virtual const std::string getPuzzleName() const override;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Solutions to the Advent Of Code 2024.
|
// Solutions to the Advent Of Code 2024.
|
||||||
// Copyright (C) 2024 Stefan Müller
|
// Copyright (C) 2024-2025 Stefan Müller
|
||||||
//
|
//
|
||||||
// This program is free software: you can redistribute it and/or modify it under
|
// 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
|
// the terms of the GNU General Public License as published by the Free Software
|
||||||
@ -21,7 +21,7 @@
|
|||||||
#include <aoc/framework/LinesSolver.hpp>
|
#include <aoc/framework/LinesSolver.hpp>
|
||||||
|
|
||||||
class HoofIt
|
class HoofIt
|
||||||
: public LinesSolver
|
: public LinesSolver<long long, long long>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual const std::string getPuzzleName() const override;
|
virtual const std::string getPuzzleName() const override;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Solutions to the Advent Of Code 2024.
|
// Solutions to the Advent Of Code 2024.
|
||||||
// Copyright (C) 2024 Stefan Müller
|
// Copyright (C) 2024-2025 Stefan Müller
|
||||||
//
|
//
|
||||||
// This program is free software: you can redistribute it and/or modify it under
|
// 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
|
// the terms of the GNU General Public License as published by the Free Software
|
||||||
@ -16,9 +16,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <aoc/common/Graph.hpp>
|
#include <aoc/common/Graph.hpp>
|
||||||
#include <aoc/framework/Solver.hpp>
|
#include <aoc/framework/Solver-types.hpp>
|
||||||
|
|
||||||
class LanParty : public Solver
|
class LanParty
|
||||||
|
: public Solver<long long, std::string>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual const std::string getPuzzleName() const override;
|
virtual const std::string getPuzzleName() const override;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Solutions to the Advent Of Code 2024.
|
// Solutions to the Advent Of Code 2024.
|
||||||
// Copyright (C) 2024 Stefan Müller
|
// Copyright (C) 2024-2025 Stefan Müller
|
||||||
//
|
//
|
||||||
// This program is free software: you can redistribute it and/or modify it under
|
// 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
|
// the terms of the GNU General Public License as published by the Free Software
|
||||||
@ -17,10 +17,10 @@
|
|||||||
|
|
||||||
#include <aoc/extra/MullData.hpp>
|
#include <aoc/extra/MullData.hpp>
|
||||||
#include <aoc/extra/MullStates.hpp>
|
#include <aoc/extra/MullStates.hpp>
|
||||||
#include <aoc/framework/Solver.hpp>
|
#include <aoc/framework/Solver-types.hpp>
|
||||||
|
|
||||||
class MullItOver
|
class MullItOver
|
||||||
: public Solver
|
: public Solver<long long, long long>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MullItOver();
|
MullItOver();
|
||||||
|
@ -18,9 +18,10 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <aoc/framework/Solver.hpp>
|
#include <aoc/framework/Solver-types.hpp>
|
||||||
|
|
||||||
class PlutonianPebbles : public Solver
|
class PlutonianPebbles
|
||||||
|
: public Solver<long long, long long>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual const std::string getPuzzleName() const override;
|
virtual const std::string getPuzzleName() const override;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Solutions to the Advent Of Code 2024.
|
// Solutions to the Advent Of Code 2024.
|
||||||
// Copyright (C) 2024 Stefan Müller
|
// Copyright (C) 2024-2025 Stefan Müller
|
||||||
//
|
//
|
||||||
// This program is free software: you can redistribute it and/or modify it under
|
// 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
|
// the terms of the GNU General Public License as published by the Free Software
|
||||||
@ -18,10 +18,10 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <aoc/common/Grid.hpp>
|
#include <aoc/common/Grid.hpp>
|
||||||
#include <aoc/framework/Solver.hpp>
|
#include <aoc/framework/Solver-types.hpp>
|
||||||
|
|
||||||
class PrintQueue
|
class PrintQueue
|
||||||
: public Solver
|
: public Solver<long long, long long>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PrintQueue();
|
PrintQueue();
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Solutions to the Advent Of Code 2024.
|
// Solutions to the Advent Of Code 2024.
|
||||||
// Copyright (C) 2024 Stefan Müller
|
// Copyright (C) 2024-2025 Stefan Müller
|
||||||
//
|
//
|
||||||
// This program is free software: you can redistribute it and/or modify it under
|
// 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
|
// the terms of the GNU General Public License as published by the Free Software
|
||||||
@ -17,10 +17,10 @@
|
|||||||
|
|
||||||
#include <aoc/common/Slope.hpp>
|
#include <aoc/common/Slope.hpp>
|
||||||
#include <aoc/extra/RedNosedReportData.hpp>
|
#include <aoc/extra/RedNosedReportData.hpp>
|
||||||
#include <aoc/framework/Solver.hpp>
|
#include <aoc/framework/Solver-types.hpp>
|
||||||
|
|
||||||
class RedNosedReports
|
class RedNosedReports
|
||||||
: public Solver
|
: public Solver<long long, long long>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual const std::string getPuzzleName() const override;
|
virtual const std::string getPuzzleName() const override;
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
#include <aoc/framework/LinesSolver.hpp>
|
#include <aoc/framework/LinesSolver.hpp>
|
||||||
|
|
||||||
class ReindeerMaze
|
class ReindeerMaze
|
||||||
: public LinesSolver
|
: public LinesSolver<long long, long long>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ReindeerMaze(const int inputFileNameSuffix = 0);
|
ReindeerMaze(const int inputFileNameSuffix = 0);
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
#include <aoc/framework/LinesSolver.hpp>
|
#include <aoc/framework/LinesSolver.hpp>
|
||||||
|
|
||||||
class ResonantCollinearity
|
class ResonantCollinearity
|
||||||
: public LinesSolver
|
: public LinesSolver<long long, long long>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual const std::string getPuzzleName() const override;
|
virtual const std::string getPuzzleName() const override;
|
||||||
|
@ -19,10 +19,10 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <aoc/common/Point2.hpp>
|
#include <aoc/common/Point2.hpp>
|
||||||
#include <aoc/framework/Solver.hpp>
|
#include <aoc/framework/Solver-types.hpp>
|
||||||
|
|
||||||
class RestroomRedoubt
|
class RestroomRedoubt
|
||||||
: public Solver
|
: public Solver<long long, long long>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RestroomRedoubt(const int width = 101, const int height = 103, const bool runPart2 = true);
|
RestroomRedoubt(const int width = 101, const int height = 103, const bool runPart2 = true);
|
||||||
|
@ -18,10 +18,10 @@
|
|||||||
#include <aoc/common/Lines.hpp>
|
#include <aoc/common/Lines.hpp>
|
||||||
#include <aoc/extra/WarehouseBoxPusher.hpp>
|
#include <aoc/extra/WarehouseBoxPusher.hpp>
|
||||||
#include <aoc/extra/WarehouseWideBoxPusher.hpp>
|
#include <aoc/extra/WarehouseWideBoxPusher.hpp>
|
||||||
#include <aoc/framework/LinesSolver.hpp>
|
#include <aoc/framework/LinesSolver-types.hpp>
|
||||||
|
|
||||||
class WarehouseWoes
|
class WarehouseWoes
|
||||||
: public LinesSolver
|
: public LinesSolver<long long, long long>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WarehouseWoes(const int inputFileNameSuffix = 0);
|
WarehouseWoes(const int inputFileNameSuffix = 0);
|
||||||
|
@ -13,29 +13,36 @@
|
|||||||
// You should have received a copy of the GNU General Public License along with
|
// You should have received a copy of the GNU General Public License along with
|
||||||
// this program. If not, see <http://www.gnu.org/licenses/>.
|
// this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
#include <aoc/framework/LinesSolver.hpp>
|
#include <aoc/framework/LinesSolver.hpp>
|
||||||
|
|
||||||
LinesSolver::LinesSolver(const int inputFileNameSuffix)
|
template <typename T1, typename T2>
|
||||||
: Solver{ inputFileNameSuffix }
|
LinesSolver<T1, T2>::LinesSolver(const int inputFileNameSuffix)
|
||||||
|
: Solver<T1, T2> { inputFileNameSuffix }
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void LinesSolver::processDataLine(const std::string& line)
|
template <typename T1, typename T2>
|
||||||
|
void LinesSolver<T1, T2>::processDataLine(const std::string& line)
|
||||||
{
|
{
|
||||||
lines.push_back(line);
|
lines.push_back(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LinesSolver::isInBounds(const Point2& point) const
|
template <typename T1, typename T2>
|
||||||
|
bool LinesSolver<T1, T2>::isInBounds(const Point2& point) const
|
||||||
{
|
{
|
||||||
return lines.isInBounds(point);
|
return lines.isInBounds(point);
|
||||||
}
|
}
|
||||||
|
|
||||||
char LinesSolver::getCharAt(const Point2& point) const
|
template <typename T1, typename T2>
|
||||||
|
char LinesSolver<T1, T2>::getCharAt(const Point2& point) const
|
||||||
{
|
{
|
||||||
return lines.getCharAt(point);
|
return lines.getCharAt(point);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LinesSolver::setCharAt(const Point2& point, const char value)
|
template <typename T1, typename T2>
|
||||||
|
void LinesSolver<T1, T2>::setCharAt(const Point2& point, const char value)
|
||||||
{
|
{
|
||||||
lines.setCharAt(point, value);
|
lines.setCharAt(point, value);
|
||||||
}
|
}
|
18
include/aoc/framework/LinesSolver-types.hpp
Normal file
18
include/aoc/framework/LinesSolver-types.hpp
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
// Solutions to the Advent Of Code 2024.
|
||||||
|
// Copyright (C) 2025 Stefan Müller
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify it under
|
||||||
|
// the terms of the GNU General Public License as published by the Free Software
|
||||||
|
// Foundation, either version 3 of the License, or (at your option) any later
|
||||||
|
// version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License along with
|
||||||
|
// this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include <aoc/framework/LinesSolver-impl.hpp>
|
||||||
|
|
||||||
|
template class LinesSolver<long long, long long>;
|
@ -21,8 +21,9 @@
|
|||||||
#include <aoc/common/Point2.hpp>
|
#include <aoc/common/Point2.hpp>
|
||||||
#include <aoc/framework/Solver.hpp>
|
#include <aoc/framework/Solver.hpp>
|
||||||
|
|
||||||
|
template <typename T1, typename T2>
|
||||||
class LinesSolver
|
class LinesSolver
|
||||||
: public Solver
|
: public Solver<T1, T2>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LinesSolver(const int inputFileNameSuffix = 0);
|
LinesSolver(const int inputFileNameSuffix = 0);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Solutions to the Advent Of Code 2024.
|
// Solutions to the Advent Of Code 2024.
|
||||||
// Copyright (C) 2024 Stefan Müller
|
// Copyright (C) 2024-2025 Stefan Müller
|
||||||
//
|
//
|
||||||
// This program is free software: you can redistribute it and/or modify it under
|
// 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
|
// the terms of the GNU General Public License as published by the Free Software
|
||||||
@ -13,16 +13,20 @@
|
|||||||
// You should have received a copy of the GNU General Public License along with
|
// You should have received a copy of the GNU General Public License along with
|
||||||
// this program. If not, see <http://www.gnu.org/licenses/>.
|
// this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
#include <aoc/framework/Solver.hpp>
|
#include <aoc/framework/Solver.hpp>
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
Solver::Solver(const int inputFileNameSuffix)
|
template <typename T1, typename T2>
|
||||||
: inputFileNameSuffix_{ inputFileNameSuffix }, part1{ 0 }, part2{ 0 }
|
Solver<T1, T2>::Solver(const int inputFileNameSuffix)
|
||||||
|
: inputFileNameSuffix_{ inputFileNameSuffix }, part1{}, part2{}
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string Solver::getInputFileName() const
|
template <typename T1, typename T2>
|
||||||
|
const std::string Solver<T1, T2>::getInputFileName() const
|
||||||
{
|
{
|
||||||
std::ostringstream stream;
|
std::ostringstream stream;
|
||||||
stream << clean(getPuzzleName());
|
stream << clean(getPuzzleName());
|
||||||
@ -34,17 +38,20 @@ const std::string Solver::getInputFileName() const
|
|||||||
return stream.str();
|
return stream.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
long long int Solver::getResultPart1() const
|
template <typename T1, typename T2>
|
||||||
|
const T1& Solver<T1, T2>::getResultPart1() const
|
||||||
{
|
{
|
||||||
return part1;
|
return part1;
|
||||||
}
|
}
|
||||||
|
|
||||||
long long int Solver::getResultPart2() const
|
template <typename T1, typename T2>
|
||||||
|
const T2& Solver<T1, T2>::getResultPart2() const
|
||||||
{
|
{
|
||||||
return part2;
|
return part2;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Solver::clean(const std::string& original) const
|
template <typename T1, typename T2>
|
||||||
|
std::string Solver<T1, T2>::clean(const std::string& original) const
|
||||||
{
|
{
|
||||||
std::string cleaned{ original };
|
std::string cleaned{ original };
|
||||||
size_t start_pos = 0;
|
size_t start_pos = 0;
|
22
include/aoc/framework/Solver-types.hpp
Normal file
22
include/aoc/framework/Solver-types.hpp
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// Solutions to the Advent Of Code 2024.
|
||||||
|
// Copyright (C) 2025 Stefan Müller
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify it under
|
||||||
|
// the terms of the GNU General Public License as published by the Free Software
|
||||||
|
// Foundation, either version 3 of the License, or (at your option) any later
|
||||||
|
// version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License along with
|
||||||
|
// this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include <aoc/framework/Solver-impl.hpp>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
template class Solver<long long, long long>;
|
||||||
|
template class Solver<long long, std::string>;
|
||||||
|
template class Solver<std::string, std::string>;
|
@ -1,5 +1,5 @@
|
|||||||
// Solutions to the Advent Of Code 2024.
|
// Solutions to the Advent Of Code 2024.
|
||||||
// Copyright (C) 2024 Stefan Müller
|
// Copyright (C) 2024-2025 Stefan Müller
|
||||||
//
|
//
|
||||||
// This program is free software: you can redistribute it and/or modify it under
|
// 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
|
// the terms of the GNU General Public License as published by the Free Software
|
||||||
@ -17,21 +17,22 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
template <typename T1, typename T2>
|
||||||
class Solver
|
class Solver
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Solver(const int inputFileNameSuffix = 0);
|
Solver(const int inputFileNameSuffix = 0);
|
||||||
virtual ~Solver(){};
|
virtual ~Solver() {};
|
||||||
const std::string getInputFileName() const;
|
const std::string getInputFileName() const;
|
||||||
virtual const std::string getPuzzleName() const = 0;
|
virtual const std::string getPuzzleName() const = 0;
|
||||||
virtual const int getPuzzleDay() const = 0;
|
virtual const int getPuzzleDay() const = 0;
|
||||||
virtual void processDataLine(const std::string& line) = 0;
|
virtual void processDataLine(const std::string& line) = 0;
|
||||||
virtual void finish() = 0;
|
virtual void finish() = 0;
|
||||||
long long int getResultPart1() const;
|
const T1& getResultPart1() const;
|
||||||
long long int getResultPart2() const;
|
const T2& getResultPart2() const;
|
||||||
protected:
|
protected:
|
||||||
long long int part1;
|
T1 part1;
|
||||||
long long int part2;
|
T2 part2;
|
||||||
private:
|
private:
|
||||||
int inputFileNameSuffix_;
|
int inputFileNameSuffix_;
|
||||||
std::string clean(const std::string& original) const;
|
std::string clean(const std::string& original) const;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Solutions to the Advent Of Code 2024.
|
// Solutions to the Advent Of Code 2024.
|
||||||
// Copyright (C) 2024 Stefan Müller
|
// Copyright (C) 2024-2025 Stefan Müller
|
||||||
//
|
//
|
||||||
// This program is free software: you can redistribute it and/or modify it under
|
// 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
|
// the terms of the GNU General Public License as published by the Free Software
|
||||||
@ -16,6 +16,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -26,7 +28,28 @@ class SolverEngine
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SolverEngine(const std::vector<std::string>& inputPaths);
|
SolverEngine(const std::vector<std::string>& inputPaths);
|
||||||
void run(Solver& solver);
|
|
||||||
|
template <typename T1, typename T2>
|
||||||
|
void run(Solver<T1, T2>& solver)
|
||||||
|
{
|
||||||
|
std::cout << "\n--- Day " << solver.getPuzzleDay() << ": " << solver.getPuzzleName() << " ---\n";
|
||||||
|
|
||||||
|
auto fullFilePath = tryGetValidFullInputFilePath(solver.getInputFileName());
|
||||||
|
if (fullFilePath != "")
|
||||||
|
{
|
||||||
|
std::string line;
|
||||||
|
std::ifstream inputFile{ fullFilePath };
|
||||||
|
while (std::getline(inputFile, line))
|
||||||
|
{
|
||||||
|
solver.processDataLine(line);
|
||||||
|
}
|
||||||
|
inputFile.close();
|
||||||
|
|
||||||
|
solver.finish();
|
||||||
|
|
||||||
|
std::cout << "Part 1: " << solver.getResultPart1() << "\nPart 2: " << solver.getResultPart2() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
std::vector<std::string> inputPaths_;
|
std::vector<std::string> inputPaths_;
|
||||||
std::filesystem::path tryGetValidFullInputFilePath(const std::string& inputFileName);
|
std::filesystem::path tryGetValidFullInputFilePath(const std::string& inputFileName);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Solutions to the Advent Of Code 2024.
|
// Solutions to the Advent Of Code 2024.
|
||||||
// Copyright (C) 2024 Stefan Müller
|
// Copyright (C) 2024-2025 Stefan Müller
|
||||||
//
|
//
|
||||||
// This program is free software: you can redistribute it and/or modify it under
|
// 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
|
// the terms of the GNU General Public License as published by the Free Software
|
||||||
@ -15,35 +15,11 @@
|
|||||||
|
|
||||||
#include <aoc/framework/SolverEngine.hpp>
|
#include <aoc/framework/SolverEngine.hpp>
|
||||||
|
|
||||||
#include <fstream>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
SolverEngine::SolverEngine(const std::vector<std::string>& inputPaths)
|
SolverEngine::SolverEngine(const std::vector<std::string>& inputPaths)
|
||||||
: inputPaths_{ inputPaths }
|
: inputPaths_{ inputPaths }
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void SolverEngine::run(Solver& solver)
|
|
||||||
{
|
|
||||||
std::cout << "\n--- Day " << solver.getPuzzleDay() << ": " << solver.getPuzzleName() << " ---\n";
|
|
||||||
|
|
||||||
auto fullFilePath = tryGetValidFullInputFilePath(solver.getInputFileName());
|
|
||||||
if (fullFilePath != "")
|
|
||||||
{
|
|
||||||
std::string line;
|
|
||||||
std::ifstream inputFile{ fullFilePath };
|
|
||||||
while (std::getline(inputFile, line))
|
|
||||||
{
|
|
||||||
solver.processDataLine(line);
|
|
||||||
}
|
|
||||||
inputFile.close();
|
|
||||||
|
|
||||||
solver.finish();
|
|
||||||
|
|
||||||
std::cout << "Part 1: " << solver.getResultPart1() << "\nPart 2: " << solver.getResultPart2() << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::filesystem::path SolverEngine::tryGetValidFullInputFilePath(const std::string& inputFileName)
|
std::filesystem::path SolverEngine::tryGetValidFullInputFilePath(const std::string& inputFileName)
|
||||||
{
|
{
|
||||||
for (const auto& path : inputPaths_)
|
for (const auto& path : inputPaths_)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Solutions to the Advent Of Code 2024.
|
// Solutions to the Advent Of Code 2024.
|
||||||
// Copyright (C) 2024 Stefan Müller
|
// Copyright (C) 2024-2025 Stefan Müller
|
||||||
//
|
//
|
||||||
// This program is free software: you can redistribute it and/or modify it under
|
// 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
|
// the terms of the GNU General Public License as published by the Free Software
|
||||||
@ -24,11 +24,13 @@
|
|||||||
class TestContext
|
class TestContext
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void run(const std::unique_ptr<Solver>&& solver, const long long int expected1, const long long int expected2,
|
void run(const std::unique_ptr<Solver<long long, long long>>&& solver, const long long expected1,
|
||||||
|
const long long expected2, const std::vector<std::string>& inputPaths);
|
||||||
|
void run(const std::unique_ptr<Solver<long long, std::string>>&& solver, const long long expected1,
|
||||||
|
const std::string expected2, const std::vector<std::string>& inputPaths);
|
||||||
|
void runPart1(const std::unique_ptr<Solver<long long, long long>>&& solver, const long long expected,
|
||||||
const std::vector<std::string>& inputPaths);
|
const std::vector<std::string>& inputPaths);
|
||||||
void runPart1(const std::unique_ptr<Solver>&& solver, const long long int expected,
|
void runPart2(const std::unique_ptr<Solver<long long, long long>>&& solver, const long long expected,
|
||||||
const std::vector<std::string>& inputPaths);
|
|
||||||
void runPart2(const std::unique_ptr<Solver>&& solver, const long long int expected,
|
|
||||||
const std::vector<std::string>& inputPaths);
|
const std::vector<std::string>& inputPaths);
|
||||||
std::vector<std::string> getInputPaths() const;
|
std::vector<std::string> getInputPaths() const;
|
||||||
std::vector<std::string> getExampleInputPaths() const;
|
std::vector<std::string> getExampleInputPaths() const;
|
||||||
|
@ -275,10 +275,10 @@ TEST_CASE("[LanPartyTests]")
|
|||||||
TestContext test;
|
TestContext test;
|
||||||
SECTION("FullData")
|
SECTION("FullData")
|
||||||
{
|
{
|
||||||
test.run(std::make_unique<LanParty>(), 1230, 0, test.getInputPaths());
|
test.run(std::make_unique<LanParty>(), 1230, "", test.getInputPaths());
|
||||||
}
|
}
|
||||||
SECTION("ExampleData")
|
SECTION("ExampleData")
|
||||||
{
|
{
|
||||||
test.run(std::make_unique<LanParty>(), 7, 0, test.getExampleInputPaths());
|
test.run(std::make_unique<LanParty>(), 7, "", test.getExampleInputPaths());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Solutions to the Advent Of Code 2024.
|
// Solutions to the Advent Of Code 2024.
|
||||||
// Copyright (C) 2024 Stefan Müller
|
// Copyright (C) 2024-2025 Stefan Müller
|
||||||
//
|
//
|
||||||
// This program is free software: you can redistribute it and/or modify it under
|
// 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
|
// the terms of the GNU General Public License as published by the Free Software
|
||||||
@ -19,8 +19,8 @@
|
|||||||
|
|
||||||
#include <aoc/framework/SolverEngine.hpp>
|
#include <aoc/framework/SolverEngine.hpp>
|
||||||
|
|
||||||
void TestContext::run(const std::unique_ptr<Solver>&& solver, const long long int expected1,
|
void TestContext::run(const std::unique_ptr<Solver<long long, long long>>&& solver, const long long expected1,
|
||||||
const long long int expected2, const std::vector<std::string>& inputPaths)
|
const long long expected2, const std::vector<std::string>& inputPaths)
|
||||||
{
|
{
|
||||||
SolverEngine solverEngine{ inputPaths };
|
SolverEngine solverEngine{ inputPaths };
|
||||||
solverEngine.run(*solver);
|
solverEngine.run(*solver);
|
||||||
@ -29,7 +29,17 @@ void TestContext::run(const std::unique_ptr<Solver>&& solver, const long long in
|
|||||||
REQUIRE(expected2 == solver->getResultPart2());
|
REQUIRE(expected2 == solver->getResultPart2());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestContext::runPart1(const std::unique_ptr<Solver>&& solver, const long long int expected,
|
void TestContext::run(const std::unique_ptr<Solver<long long, std::string>>&& solver, const long long expected1,
|
||||||
|
const std::string expected2, const std::vector<std::string>& inputPaths)
|
||||||
|
{
|
||||||
|
SolverEngine solverEngine{ inputPaths };
|
||||||
|
solverEngine.run(*solver);
|
||||||
|
|
||||||
|
REQUIRE(expected1 == solver->getResultPart1());
|
||||||
|
REQUIRE(expected2 == solver->getResultPart2());
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestContext::runPart1(const std::unique_ptr<Solver<long long, long long>>&& solver, const long long expected,
|
||||||
const std::vector<std::string>& inputPaths)
|
const std::vector<std::string>& inputPaths)
|
||||||
{
|
{
|
||||||
SolverEngine solverEngine{ inputPaths };
|
SolverEngine solverEngine{ inputPaths };
|
||||||
@ -38,7 +48,7 @@ void TestContext::runPart1(const std::unique_ptr<Solver>&& solver, const long lo
|
|||||||
REQUIRE(expected == solver->getResultPart1());
|
REQUIRE(expected == solver->getResultPart1());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestContext::runPart2(const std::unique_ptr<Solver>&& solver, const long long int expected,
|
void TestContext::runPart2(const std::unique_ptr<Solver<long long, long long>>&& solver, const long long expected,
|
||||||
const std::vector<std::string>& inputPaths)
|
const std::vector<std::string>& inputPaths)
|
||||||
{
|
{
|
||||||
SolverEngine solverEngine{ inputPaths };
|
SolverEngine solverEngine{ inputPaths };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user