-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDec18_part1.cpp
More file actions
62 lines (46 loc) · 1.22 KB
/
Copy pathDec18_part1.cpp
File metadata and controls
62 lines (46 loc) · 1.22 KB
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
55
56
57
58
59
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <sstream>
#include <set>
using vec = std::vector<int>;
using Pointset = std::set<vec>;
void print(const Pointset& wallPoints){
for (auto it=wallPoints.begin();it!=wallPoints.end();++it){
std::cout<<it->at(0)<<' '<<it->at(1)<<' '<<it->at(2)<<'\n';
}
}
vec sum_vec(const vec& v1,const vec& v2){
vec v3{v1};
for (int i=0;i<v1.size();++i){
v3[i] += v2[i];
}
return v3;
}
int main(){
std::ifstream file("data18.txt");
std::string str{};
Pointset wallPoints{};
int coord_x{};
int coord_y{};
int coord_z{};
char dummy{};
while(getline(file,str)){
std::stringstream ss{str};
ss>>coord_x>>dummy;
ss>>coord_y>>dummy;
ss>>coord_z;
wallPoints.insert({coord_x,coord_y,coord_z});
}
std::vector<vec> directions = {{1,0,0},{-1,0,0},{0,1,0},{0,-1,0},{0,0,1},{0,0,-1}};
int free_faces{};
for (vec cur: wallPoints){
for (vec dir: directions){
vec neighbour{sum_vec(cur,dir)};
if (wallPoints.find(neighbour)==wallPoints.end()) ++free_faces;
}
}
std::cout<<free_faces<<'\n';
return 0;
}