Add solution for "Day 14: Restroom Redoubt", part 2

This commit is contained in:
2025-02-25 20:16:03 +01:00
parent a75535bab7
commit 8d75bdfbef
8 changed files with 128 additions and 7 deletions

View File

@@ -15,8 +15,26 @@
#pragma once
#include <tuple>
class Math
{
public:
/// <summary>
/// Calculates an integer exponentiation.
/// </summary>
/// <param name="base">Base of the exponentiation.</param>
/// <param name="exponent">Exponent of the exponentiation</param>
/// <returns>'base' raised to the power of 'exponent'.</returns>
static int ipow(const int base, const int exponent);
/// <summary>
/// Calculates the greatest common divisor gcd(a, b) and the coefficients x and y of Bézout's identity
/// ax + by = gcd(a, b). If a and b are coprime, then x is the modular multiplicative inverse of a modulo b, and y
/// is the modular multiplicative inverse of b modulo a.
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns>A tuple of the gcd(a, b), x, and y.</returns>
static std::tuple<int, int, int> extendedEuclid(const int a, const int b);
};

View File

@@ -43,4 +43,5 @@ class Point2
Point2& operator+=(const Point2& rhs);
Point2& operator-=(const Point2& rhs);
Point2& operator*=(const int rhs);
int& operator[](size_t coordinateIndex);
};

View File

@@ -16,14 +16,16 @@
#pragma once
#include <array>
#include <vector>
#include <aoc/Point2.hpp>
#include <aoc/Solver.hpp>
class RestroomRedoubt
: public Solver
{
public:
RestroomRedoubt(const int width = 101, const int height = 103);
RestroomRedoubt(const int width = 101, const int height = 103, const bool runPart2 = true);
virtual const std::string getPuzzleName() const override;
virtual const int getPuzzleDay() const override;
virtual void processDataLine(const std::string& line) override;
@@ -33,6 +35,10 @@ class RestroomRedoubt
const int height_;
const int halfWidth_;
const int halfHeight_;
const bool runPart2_;
std::array<int, 4> quadrants_;
std::vector<std::pair<Point2, Point2>> robots_;
static constexpr int getNPredictionSeconds();
static constexpr int getEasterEggThreshold();
void findEasterEgg();
};