369 lines
9.2 KiB
C++
369 lines
9.2 KiB
C++
// Solutions to the Advent Of Code 2024.
|
|
// Copyright (C) 2024-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 <catch2/catch_test_macros.hpp>
|
|
|
|
#include <aocTests/TestContext.hpp>
|
|
|
|
// Solver implementations in day order.
|
|
#include <aoc/HistorianHysteria.hpp>
|
|
#include <aoc/RedNosedReports.hpp>
|
|
#include <aoc/MullItOver.hpp>
|
|
#include <aoc/CeresSearch.hpp>
|
|
#include <aoc/PrintQueue.hpp>
|
|
#include <aoc/GuardGallivant.hpp>
|
|
#include <aoc/BridgeRepair.hpp>
|
|
#include <aoc/ResonantCollinearity.hpp>
|
|
#include <aoc/DiskFragmenter.hpp>
|
|
#include <aoc/HoofIt.hpp>
|
|
#include <aoc/PlutonianPebbles.hpp>
|
|
#include <aoc/GardenGroups.hpp>
|
|
#include <aoc/ClawContraption.hpp>
|
|
#include <aoc/RestroomRedoubt.hpp>
|
|
#include <aoc/WarehouseWoes.hpp>
|
|
#include <aoc/ReindeerMaze.hpp>
|
|
#include <aoc/ChronospatialComputer.hpp>
|
|
#include <aoc/RamRun.hpp>
|
|
#include <aoc/LinenLayout.hpp>
|
|
#include <aoc/LanParty.hpp>
|
|
|
|
#define REQUIRE_MESSAGE(cond, msg) if (!(cond)) { INFO(msg); REQUIRE(cond); }
|
|
|
|
TEST_CASE("[HistorianHysteriaTests]")
|
|
{
|
|
TestContext test;
|
|
SECTION("FullData")
|
|
{
|
|
test.runFull(std::make_unique<HistorianHysteria>(), 2176849, 23384288);
|
|
}
|
|
SECTION("ExampleData")
|
|
{
|
|
test.runExample(std::make_unique<HistorianHysteria>(), 11, 31);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("[RedNosedReportsTests]")
|
|
{
|
|
TestContext test;
|
|
SECTION("FullData")
|
|
{
|
|
test.runFull(std::make_unique<RedNosedReports>(), 472, 520);
|
|
}
|
|
SECTION("ExampleData")
|
|
{
|
|
test.runExample(std::make_unique<RedNosedReports>(), 2, 4);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("[MullItOverTests]")
|
|
{
|
|
TestContext test;
|
|
SECTION("FullData")
|
|
{
|
|
test.runFull(std::make_unique<MullItOver>(), 187833789, 94455185);
|
|
}
|
|
SECTION("ExampleData")
|
|
{
|
|
test.runExample(std::make_unique<MullItOver>(), 161, 48);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("[CeresSearchTests]")
|
|
{
|
|
TestContext test;
|
|
SECTION("FullData")
|
|
{
|
|
test.runFull(std::make_unique<CeresSearch>(), 2462, 1877);
|
|
}
|
|
SECTION("ExampleData")
|
|
{
|
|
test.runExample(std::make_unique<CeresSearch>(), 18, 9);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("[PrintQueueTests]")
|
|
{
|
|
TestContext test;
|
|
SECTION("FullData")
|
|
{
|
|
test.runFull(std::make_unique<PrintQueue>(), 5087, 4971);
|
|
}
|
|
SECTION("ExampleData")
|
|
{
|
|
test.runExample(std::make_unique<PrintQueue>(), 143, 123);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("[GuardGallivantTests]")
|
|
{
|
|
TestContext test;
|
|
SECTION("FullData")
|
|
{
|
|
test.runFull(std::make_unique<GuardGallivant>(), 4665, 1688);
|
|
}
|
|
SECTION("ExampleData")
|
|
{
|
|
test.runExample(std::make_unique<GuardGallivant>(), 41, 6);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("[BridgeRepairTests]")
|
|
{
|
|
TestContext test;
|
|
SECTION("FullData")
|
|
{
|
|
test.runFull(std::make_unique<BridgeRepair>(), 12839601725877, 149956401519484);
|
|
}
|
|
SECTION("ExampleData")
|
|
{
|
|
test.runExample(std::make_unique<BridgeRepair>(), 3749, 11387);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("[ResonantCollinearityTests]")
|
|
{
|
|
TestContext test;
|
|
SECTION("FullData")
|
|
{
|
|
test.runFull(std::make_unique<ResonantCollinearity>(), 426, 1359);
|
|
}
|
|
SECTION("ExampleData")
|
|
{
|
|
test.runExample(std::make_unique<ResonantCollinearity>(), 14, 34);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("[DiskFragmenterTests]")
|
|
{
|
|
TestContext test;
|
|
SECTION("FullData")
|
|
{
|
|
test.runFull(std::make_unique<DiskFragmenter>(), 6401092019345, 6431472344710);
|
|
}
|
|
SECTION("ExampleData")
|
|
{
|
|
test.runExample(std::make_unique<DiskFragmenter>(), 1928, 2858);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("[HoofItTests]")
|
|
{
|
|
TestContext test;
|
|
SECTION("FullData")
|
|
{
|
|
test.runFull(std::make_unique<HoofIt>(), 611, 1380);
|
|
}
|
|
SECTION("ExampleData")
|
|
{
|
|
test.runExample(std::make_unique<HoofIt>(), 36, 81);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("[PlutonianPebblesTests]")
|
|
{
|
|
TestContext test;
|
|
SECTION("FullData")
|
|
{
|
|
test.runFull(std::make_unique<PlutonianPebbles>(), 220999, 261936432123724);
|
|
}
|
|
SECTION("ExampleData")
|
|
{
|
|
test.runExample(std::make_unique<PlutonianPebbles>(), 55312, 65601038650482);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("[GardenGroupsTests]")
|
|
{
|
|
TestContext test;
|
|
SECTION("FullData")
|
|
{
|
|
test.runFull(std::make_unique<GardenGroups>(), 1477762, 923480);
|
|
}
|
|
SECTION("ExampleData")
|
|
{
|
|
test.runExample(std::make_unique<GardenGroups>(), 1930, 1206);
|
|
}
|
|
SECTION("ExampleData2")
|
|
{
|
|
test.runExample(std::make_unique<GardenGroups>(2), 140, 80);
|
|
}
|
|
SECTION("ExampleData3")
|
|
{
|
|
test.runExample(std::make_unique<GardenGroups>(3), 772, 436);
|
|
}
|
|
SECTION("ExampleData4")
|
|
{
|
|
test.runExamplePart2(std::make_unique<GardenGroups>(4), 236);
|
|
}
|
|
SECTION("ExampleData5")
|
|
{
|
|
test.runExamplePart2(std::make_unique<GardenGroups>(5), 368);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("[ClawContraptionTests]")
|
|
{
|
|
TestContext test;
|
|
SECTION("FullData")
|
|
{
|
|
test.runFull(std::make_unique<ClawContraption>(), 36571, 85527711500010);
|
|
}
|
|
SECTION("ExampleData")
|
|
{
|
|
test.runExample(std::make_unique<ClawContraption>(), 480, 875318608908);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("[RestroomRedoubtTests]")
|
|
{
|
|
TestContext test;
|
|
SECTION("FullData")
|
|
{
|
|
test.runFull(std::make_unique<RestroomRedoubt>(), 224969976, 7892);
|
|
}
|
|
SECTION("ExampleData")
|
|
{
|
|
test.runExample(std::make_unique<RestroomRedoubt>(11, 7, false), 12, 0);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("[WarehouseWoesTests]")
|
|
{
|
|
TestContext test;
|
|
SECTION("FullData")
|
|
{
|
|
test.runFull(std::make_unique<WarehouseWoes>(), 1515788, 1516544);
|
|
}
|
|
SECTION("ExampleData")
|
|
{
|
|
test.runExample(std::make_unique<WarehouseWoes>(), 10092, 9021);
|
|
}
|
|
SECTION("ExampleData2")
|
|
{
|
|
test.runExamplePart1(std::make_unique<WarehouseWoes>(2), 2028);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("[ReindeerMazeTests]")
|
|
{
|
|
TestContext test;
|
|
SECTION("FullData")
|
|
{
|
|
test.runFull(std::make_unique<ReindeerMaze>(), 72400, 435);
|
|
}
|
|
SECTION("ExampleData")
|
|
{
|
|
test.runExample(std::make_unique<ReindeerMaze>(), 7036, 45);
|
|
}
|
|
SECTION("ExampleData2")
|
|
{
|
|
test.runExample(std::make_unique<ReindeerMaze>(2), 11048, 64);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("[ChronospatialComputerTests]")
|
|
{
|
|
TestContext test;
|
|
SECTION("FullData")
|
|
{
|
|
test.runFull(std::make_unique<ChronospatialComputer>(), "5,0,3,5,7,6,1,5,4", 164516454365621);
|
|
}
|
|
SECTION("ExampleData")
|
|
{
|
|
test.runExamplePart1(std::make_unique<ChronospatialComputer>(), "4,6,3,5,6,3,5,2,1,0");
|
|
}
|
|
SECTION("ExampleInstruction1")
|
|
{
|
|
auto solver = std::make_unique<ChronospatialComputer>();
|
|
ChronospatialComputerState state{};
|
|
state.registers[2] = 9;
|
|
solver->runProgram({ 2, 6 }, state);
|
|
REQUIRE(1 == state.registers[1]);
|
|
}
|
|
SECTION("ExampleInstruction2")
|
|
{
|
|
auto solver = std::make_unique<ChronospatialComputer>();
|
|
ChronospatialComputerState state{};
|
|
state.registers[0] = 10;
|
|
solver->runProgram({ 5, 0, 5, 1, 5, 4 }, state);
|
|
REQUIRE("0,1,2" == state.output.str());
|
|
}
|
|
SECTION("ExampleInstruction3")
|
|
{
|
|
auto solver = std::make_unique<ChronospatialComputer>();
|
|
ChronospatialComputerState state{};
|
|
state.registers[0] = 2024;
|
|
solver->runProgram({ 0, 1, 5, 4, 3, 0 }, state);
|
|
REQUIRE(0 == state.registers[0]);
|
|
REQUIRE("4,2,5,6,7,7,7,7,3,1,0" == state.output.str());
|
|
}
|
|
SECTION("ExampleInstruction4")
|
|
{
|
|
auto solver = std::make_unique<ChronospatialComputer>();
|
|
ChronospatialComputerState state{};
|
|
state.registers[1] = 29;
|
|
solver->runProgram({ 1, 7 }, state);
|
|
REQUIRE(26 == state.registers[1]);
|
|
}
|
|
SECTION("ExampleInstruction5")
|
|
{
|
|
auto solver = std::make_unique<ChronospatialComputer>();
|
|
ChronospatialComputerState state{};
|
|
state.registers[1] = 2024;
|
|
state.registers[2] = 43690;
|
|
solver->runProgram({ 4, 0 }, state);
|
|
REQUIRE(44354 == state.registers[1]);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("[RamRunTests]")
|
|
{
|
|
TestContext test;
|
|
SECTION("FullData")
|
|
{
|
|
test.runFull(std::make_unique<RamRun>(), 248, "32,55");
|
|
}
|
|
SECTION("ExampleData")
|
|
{
|
|
test.runExample(std::make_unique<RamRun>(7, 12), 22, "6,1");
|
|
}
|
|
}
|
|
|
|
TEST_CASE("[LinenLayoutTests]")
|
|
{
|
|
TestContext test;
|
|
SECTION("FullData")
|
|
{
|
|
test.runFull(std::make_unique<LinenLayout>(), 272, 1041529704688380);
|
|
}
|
|
SECTION("ExampleData")
|
|
{
|
|
test.runExample(std::make_unique<LinenLayout>(), 6, 16);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("[LanPartyTests]")
|
|
{
|
|
TestContext test;
|
|
SECTION("FullData")
|
|
{
|
|
test.runFull(std::make_unique<LanParty>(), 1230, "");
|
|
}
|
|
SECTION("ExampleData")
|
|
{
|
|
test.runExample(std::make_unique<LanParty>(), 7, "");
|
|
}
|
|
}
|