Rename LinesSolver::getPosition()/setPosition() to getCharAt()/setCharAt()

This commit is contained in:
Stefan Müller 2025-02-04 17:50:38 +01:00
parent 54204766ec
commit 648f6d4ebc
6 changed files with 20 additions and 20 deletions

View File

@ -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
@ -28,6 +28,6 @@ class LinesSolver
protected: protected:
std::vector<std::string> lines{}; std::vector<std::string> lines{};
bool isInBounds(const Point2& point) const; bool isInBounds(const Point2& point) const;
char getPosition(const Point2& point) const; char getCharAt(const Point2& point) const;
void setPosition(const Point2& point, const char value); void setCharAt(const Point2& point, const char value);
}; };

View File

@ -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
@ -51,7 +51,7 @@ void CeresSearch::computeXmasCount(const Point2& start)
{ {
auto p{ start + d }; auto p{ start + d };
auto i{ 1 }; auto i{ 1 };
while (i < 4 && isInBounds(p) && xmas_[i] == getPosition(p)) while (i < 4 && isInBounds(p) && xmas_[i] == getCharAt(p))
{ {
p += d; p += d;
i++; i++;
@ -70,10 +70,10 @@ void CeresSearch::computeX_MasCount(const Point2& start)
auto pUR{ start + Point2::upRight }; auto pUR{ start + Point2::upRight };
auto pDL{ start + Point2::downLeft }; auto pDL{ start + Point2::downLeft };
if (isInBounds(pUL) && isInBounds(pDR) if (isInBounds(pUL) && isInBounds(pDR)
&& ((getPosition(pUL) == xmas_[1] && getPosition(pDR) == xmas_[3]) && ((getCharAt(pUL) == xmas_[1] && getCharAt(pDR) == xmas_[3])
|| (getPosition(pUL) == xmas_[3] && getPosition(pDR) == xmas_[1])) || (getCharAt(pUL) == xmas_[3] && getCharAt(pDR) == xmas_[1]))
&& ((getPosition(pUR) == xmas_[1] && getPosition(pDL) == xmas_[3]) && ((getCharAt(pUR) == xmas_[1] && getCharAt(pDL) == xmas_[3])
|| (getPosition(pUR) == xmas_[3] && getPosition(pDL) == xmas_[1]))) || (getCharAt(pUR) == xmas_[3] && getCharAt(pDL) == xmas_[1])))
{ {
part2++; part2++;
} }

View File

@ -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
@ -43,7 +43,7 @@ void GuardGallivant::finish()
auto next{ current + Point2::cardinalDirections[dirIndex] }; auto next{ current + Point2::cardinalDirections[dirIndex] };
while (isInBounds(next)) while (isInBounds(next))
{ {
if (getPosition(next) == getObstructionChar()) if (getCharAt(next) == getObstructionChar())
{ {
dirIndex = turnDirection(dirIndex); dirIndex = turnDirection(dirIndex);
} }
@ -78,9 +78,9 @@ constexpr char GuardGallivant::getObstructionChar()
void GuardGallivant::visitPosition(const Point2& current) void GuardGallivant::visitPosition(const Point2& current)
{ {
if (getPosition(current) != getVisitedChar()) if (getCharAt(current) != getVisitedChar())
{ {
setPosition(current, getVisitedChar()); setCharAt(current, getVisitedChar());
part1++; part1++;
} }
} }

View File

@ -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
@ -57,12 +57,12 @@ void HoofIt::finish()
{ {
auto trail = queue.front(); auto trail = queue.front();
queue.pop(); queue.pop();
if (getPosition(trail) != getTrailheadChar()) if (getCharAt(trail) != getTrailheadChar())
{ {
for (auto direction : Point2::cardinalDirections) for (auto direction : Point2::cardinalDirections)
{ {
Point2 p{ trail + direction }; 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()) if (trailEndsMap[p.y][p.x].empty())
{ {

View File

@ -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
@ -26,12 +26,12 @@ bool LinesSolver::isInBounds(const Point2& point) const
0 <= point.x && point.x < lines[point.y].size(); 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]; 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; lines[point.y][point.x] = value;
} }

View File

@ -53,7 +53,7 @@ constexpr char ResonantCollinearity::getEmptyChar()
void ResonantCollinearity::addNewAntenna(Grid<bool>& antinodeGrid1, Grid<bool>& antinodeGrid2, Point2&& newPosition) 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) if (!success)
{ {
// Adds the new antenna position itself as an antinode for part 2. // Adds the new antenna position itself as an antinode for part 2.