Rename LinesSolver::getPosition()/setPosition() to getCharAt()/setCharAt()
This commit is contained in:
parent
54204766ec
commit
648f6d4ebc
|
@ -1,5 +1,5 @@
|
|||
// 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
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -28,6 +28,6 @@ class LinesSolver
|
|||
protected:
|
||||
std::vector<std::string> lines{};
|
||||
bool isInBounds(const Point2& point) const;
|
||||
char getPosition(const Point2& point) const;
|
||||
void setPosition(const Point2& point, const char value);
|
||||
char getCharAt(const Point2& point) const;
|
||||
void setCharAt(const Point2& point, const char value);
|
||||
};
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// 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
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -51,7 +51,7 @@ void CeresSearch::computeXmasCount(const Point2& start)
|
|||
{
|
||||
auto p{ start + d };
|
||||
auto i{ 1 };
|
||||
while (i < 4 && isInBounds(p) && xmas_[i] == getPosition(p))
|
||||
while (i < 4 && isInBounds(p) && xmas_[i] == getCharAt(p))
|
||||
{
|
||||
p += d;
|
||||
i++;
|
||||
|
@ -70,10 +70,10 @@ void CeresSearch::computeX_MasCount(const Point2& start)
|
|||
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])))
|
||||
&& ((getCharAt(pUL) == xmas_[1] && getCharAt(pDR) == xmas_[3])
|
||||
|| (getCharAt(pUL) == xmas_[3] && getCharAt(pDR) == xmas_[1]))
|
||||
&& ((getCharAt(pUR) == xmas_[1] && getCharAt(pDL) == xmas_[3])
|
||||
|| (getCharAt(pUR) == xmas_[3] && getCharAt(pDL) == xmas_[1])))
|
||||
{
|
||||
part2++;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// 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
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -43,7 +43,7 @@ void GuardGallivant::finish()
|
|||
auto next{ current + Point2::cardinalDirections[dirIndex] };
|
||||
while (isInBounds(next))
|
||||
{
|
||||
if (getPosition(next) == getObstructionChar())
|
||||
if (getCharAt(next) == getObstructionChar())
|
||||
{
|
||||
dirIndex = turnDirection(dirIndex);
|
||||
}
|
||||
|
@ -78,9 +78,9 @@ constexpr char GuardGallivant::getObstructionChar()
|
|||
|
||||
void GuardGallivant::visitPosition(const Point2& current)
|
||||
{
|
||||
if (getPosition(current) != getVisitedChar())
|
||||
if (getCharAt(current) != getVisitedChar())
|
||||
{
|
||||
setPosition(current, getVisitedChar());
|
||||
setCharAt(current, getVisitedChar());
|
||||
part1++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// 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
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -57,12 +57,12 @@ void HoofIt::finish()
|
|||
{
|
||||
auto trail = queue.front();
|
||||
queue.pop();
|
||||
if (getPosition(trail) != getTrailheadChar())
|
||||
if (getCharAt(trail) != getTrailheadChar())
|
||||
{
|
||||
for (auto direction : Point2::cardinalDirections)
|
||||
{
|
||||
Point2 p{ trail + direction };
|
||||
if (isInBounds(p) && getPosition(p) + 1 == getPosition(trail))
|
||||
if (isInBounds(p) && getCharAt(p) + 1 == getCharAt(trail))
|
||||
{
|
||||
if (trailEndsMap[p.y][p.x].empty())
|
||||
{
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// 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
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -26,12 +26,12 @@ bool LinesSolver::isInBounds(const Point2& point) const
|
|||
0 <= point.x && point.x < lines[point.y].size();
|
||||
}
|
||||
|
||||
char LinesSolver::getPosition(const Point2& point) const
|
||||
char LinesSolver::getCharAt(const Point2& point) const
|
||||
{
|
||||
return lines[point.y][point.x];
|
||||
}
|
||||
|
||||
void LinesSolver::setPosition(const Point2& point, const char value)
|
||||
void LinesSolver::setCharAt(const Point2& point, const char value)
|
||||
{
|
||||
lines[point.y][point.x] = value;
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ constexpr char ResonantCollinearity::getEmptyChar()
|
|||
|
||||
void ResonantCollinearity::addNewAntenna(Grid<bool>& antinodeGrid1, Grid<bool>& antinodeGrid2, Point2&& newPosition)
|
||||
{
|
||||
const auto [it, success] = antennas_.insert({ getPosition(newPosition), { newPosition } });
|
||||
const auto [it, success] = antennas_.insert({ getCharAt(newPosition), { newPosition } });
|
||||
if (!success)
|
||||
{
|
||||
// Adds the new antenna position itself as an antinode for part 2.
|
||||
|
|
Loading…
Reference in New Issue