-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathday_03a.cpp
54 lines (49 loc) · 1.32 KB
/
day_03a.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
45
46
47
48
49
50
51
52
53
54
#include <fstream>
#include <iostream>
#include <string>
#include <unordered_set>
struct Point {
int row;
int col;
bool operator == (const Point& p) const {
return p.row ==row && p.col == col;
}
};
struct PointHasher {
std::size_t operator () (const Point& p) const {
return (p.row << 10) + p.col;
}
};
int main(int argc, char* argv[]) {
std::string input = "../input/day_03_input";
if (argc > 1) {
input = argv[1];
}
std::string line;
std::ifstream file(input);
while (std::getline(file, line)) { // to allow for sample input
std::unordered_set<Point, PointHasher> seen;
Point current;
current.row = 0;
current.col = 0;
seen.insert(current);
for(const auto ele : line) {
if (ele == '<') {
current.col--;
} else if (ele == '>') {
current.col++;
} else if (ele == '^') {
current.row--;
} else if (ele == 'v') {
current.row++;
} else {
std::cout << "This should not happen";
std::cout << "Unknown symbol: " << ele << '\n';
exit(0);
}
seen.insert(current);
}
std::cout << seen.size() << '\n';
}
return 0;
}