Added year directories for advent of code

This commit is contained in:
2022-12-02 13:37:41 +01:00
parent 27d00340b9
commit 6c9525248e
31 changed files with 275 additions and 0 deletions

View File

@@ -0,0 +1,87 @@
#include <bits/stdc++.h>
using namespace std;
string file_name = "9.txt";
// string file_name = "test.txt";
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
vector<vector<int>> heights;
ifstream file_stream;
file_stream.open(file_name);
if(file_stream.is_open()){
string line;
while(getline(file_stream, line)){
vector<int> line_input;
for(const char &c : line){
line_input.push_back(c - '0');
}
heights.push_back(line_input);
}
}
// Test input parsing
// for(auto v : heights){
// for(auto i : v){
// cout << i;
// } cout << endl;
// } cout << endl;
size_t HEIGHT = heights.size() - 1, WIDTH = heights[0].size() - 1;
int result = 0;
for(size_t i = 0; i <= HEIGHT; ++i){
for(size_t j = 0; j <= WIDTH; ++j){
bool lowest = true;
int cur = heights[i][j];
// Check on corner cases (ha literally)
if(i != 0){
lowest &= cur < heights[i - 1][j];
}
if(i != HEIGHT){
lowest &= cur < heights[i + 1][j];
}
if(j != 0){
lowest &= cur < heights[i][j - 1];
}
if(j != WIDTH){
lowest &= cur < heights[i][j + 1];
}
if(lowest){
result += cur + 1;
}
}
}
cout << result << endl;
// For the second part we need to do some kind of scanning of all points line by line
// in which we need to make sure we don't scan points multiple times.
// Im thinking of something akin to line segment intersection with a scan line
// So keep track of which regions are currently present on the scan line
// One region can occur multiple times on the scane line,
// so we have to look into which events exist
// But now we have to keep track of the previous lines all the time as well,
// so it is not exactly the same as a scanning line thing
// I think this doesn't work, in the worst case I think you can have situations
// in which each points gets visited n times or n / 2 or something
cout << flush;
return 0;
}