-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday17_robot-rescue.cpp
45 lines (37 loc) · 1.46 KB
/
day17_robot-rescue.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <cassert>
#include "IntcodeComputer.cpp"
#include "coordinate.cpp"
enum class ASCII { newline = 10, hash = 35, dot = 46 };
int main(int argc, char const *argv[])
{
// Part 1
const auto p1Input = getPuzzleInput("inputs/aoc_day17_1.txt").front();
const auto vacuumRobot = runProgram(p1Input);
Coordinate currentCoord {0, 0};
unordered_set<Coordinate, CoordinateHash> scafoldCoordinates;
for(const auto pixel : vacuumRobot.outputs) {
if(pixel == static_cast<IntCode>(ASCII::hash)) {
scafoldCoordinates.insert(currentCoord);
}
if(pixel == static_cast<IntCode>(ASCII::newline)) {
currentCoord.x = 0;
currentCoord.y += 1;
} else {
currentCoord.x += 1;
}
}
size_t alignementParameterSum = 0;
for(const auto sc : scafoldCoordinates) {
const bool continueUp = scafoldCoordinates.find({sc.x, sc.y+1}) != scafoldCoordinates.cend();
const bool continueDown = scafoldCoordinates.find({sc.x, sc.y-1}) != scafoldCoordinates.cend();
const bool continueLeft = scafoldCoordinates.find({sc.x+1, sc.y}) != scafoldCoordinates.cend();
const bool continueRight = scafoldCoordinates.find({sc.x-1, sc.y}) != scafoldCoordinates.cend();
const auto isIntersection = continueUp && continueDown && continueLeft && continueRight;
if(isIntersection) {
alignementParameterSum += sc.x * sc.y;
}
}
cout << "Part1, alignementParameterSum: " << alignementParameterSum << "\n";
return 0;
}