Update HoofIt to use Grid
This commit is contained in:
parent
7aeaab2c49
commit
60a952fd5e
|
@ -19,6 +19,7 @@
|
|||
#include <queue>
|
||||
#include <vector>
|
||||
|
||||
#include <aoc/Grid.hpp>
|
||||
#include <aoc/Point2.hpp>
|
||||
|
||||
const std::string HoofIt::getPuzzleName() const
|
||||
|
@ -34,23 +35,14 @@ const std::string HoofIt::getInputFileName() const
|
|||
void HoofIt::finish()
|
||||
{
|
||||
std::queue<Point2> queue{};
|
||||
std::vector<std::vector<std::vector<Point2>>> trailEndsMap{};
|
||||
trailEndsMap.reserve(lines.size());
|
||||
std::vector<std::vector<int>> trailScoreMap{};
|
||||
trailScoreMap.reserve(lines.size());
|
||||
Grid<std::vector<Point2>> trailEndsMap{ lines.size(), lines[0].size() };
|
||||
Grid<int> trailScoreMap{ lines.size(), lines[0].size() };
|
||||
|
||||
for (int j = 0; j < lines.size(); j++)
|
||||
{
|
||||
std::vector<std::vector<Point2>> endsRow{};
|
||||
endsRow.reserve(lines[j].size());
|
||||
trailEndsMap.push_back(endsRow);
|
||||
std::vector<int> scoreRow(lines[j].size(), 0);
|
||||
trailScoreMap.push_back(scoreRow);
|
||||
|
||||
for (int i = 0; i < lines[j].size(); i++)
|
||||
{
|
||||
std::vector<Point2> ends{};
|
||||
trailEndsMap[j].push_back(ends);
|
||||
trailScoreMap[j][i] = 0;
|
||||
if (lines[j][i] == getTrailTopChar())
|
||||
{
|
||||
Point2 trailEnd{ i, j };
|
||||
|
@ -76,15 +68,15 @@ void HoofIt::finish()
|
|||
{
|
||||
queue.push(p);
|
||||
}
|
||||
addUnique(trailEndsMap[trail.y][trail.x], trailEndsMap[p.y][p.x]);
|
||||
trailScoreMap[p.y][p.x] += trailScoreMap[trail.y][trail.x];
|
||||
addUnique(trailEndsMap.cell(trail), trailEndsMap.cell(p));
|
||||
trailScoreMap.cell(p) += trailScoreMap.cell(trail);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
part1 += trailEndsMap[trail.y][trail.x].size();
|
||||
part2 += trailScoreMap[trail.y][trail.x];
|
||||
part1 += trailEndsMap.cell(trail).size();
|
||||
part2 += trailScoreMap.cell(trail);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue