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