Working on advent of code day 8
This commit is contained in:
115
advent_of_code/d8/main.cpp
Normal file
115
advent_of_code/d8/main.cpp
Normal file
@@ -0,0 +1,115 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
string file_name = "8.txt";
|
||||
// string file_name = "test_text.txt";
|
||||
|
||||
vector<pair<array<string, 10>, array<string, 4>>> input_text;
|
||||
|
||||
pair<array<string, 10>, array<string, 4>> parse_line(const string &s){
|
||||
istringstream ss(s);
|
||||
pair<array<string, 10>, array<string, 4>> result;
|
||||
string word;
|
||||
|
||||
for(size_t i = 0; i < 10; ++i){
|
||||
ss >> word;
|
||||
|
||||
result.first[i] = word;
|
||||
}
|
||||
|
||||
// There should be a pipe | here, which doesn't need to be put into the strings
|
||||
ss >> word;
|
||||
|
||||
for(size_t i = 0; i < 4; ++i){
|
||||
ss >> word;
|
||||
|
||||
result.second[i] = word;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
map<int, string> identify_digits(const array<string, 10> &digits){
|
||||
map<int, string> digit_strings;
|
||||
|
||||
vector<string> size_fives;
|
||||
vector<string> size_six;
|
||||
|
||||
for(size_t i = 0; i < 10; ++i){
|
||||
size_t ds = digits[i].size();
|
||||
|
||||
if(ds == 2){
|
||||
digit_strings[1] = digits[i];
|
||||
} else if(ds == 3){
|
||||
digit_strings[7] = digits[i];
|
||||
} else if(ds == 4){
|
||||
digit_strings[4] = digits[i];
|
||||
} else if(ds == 7){
|
||||
digit_strings[8] = digits[i];
|
||||
} else if(ds == 5){
|
||||
size_fives.push_back(digits[i]);
|
||||
} else if(ds == 6){
|
||||
size_six.push_back(digits[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return digit_strings;
|
||||
}
|
||||
|
||||
int main(){
|
||||
ios::sync_with_stdio(0);
|
||||
cin.tie(0);
|
||||
|
||||
|
||||
ifstream file_stream;
|
||||
file_stream.open(file_name);
|
||||
|
||||
if(file_stream.is_open()){
|
||||
string line;
|
||||
|
||||
while(getline(file_stream, line)){
|
||||
input_text.push_back(parse_line(line));
|
||||
}
|
||||
|
||||
file_stream.close();
|
||||
}
|
||||
|
||||
|
||||
// Testing the input parsing
|
||||
|
||||
// cout << input_text.size() << endl;
|
||||
// for(const auto &line : input_text){
|
||||
// for(auto word : line.first){
|
||||
// cout << word << " ";
|
||||
// }
|
||||
|
||||
// cout << "| ";
|
||||
|
||||
// for(auto word : line.second){
|
||||
// cout << word << " ";
|
||||
// }
|
||||
|
||||
// cout << endl;
|
||||
// }
|
||||
|
||||
int result = 0;
|
||||
for(const auto &line : input_text){
|
||||
for(size_t i = 0; i < 4; ++i){
|
||||
size_t w = line.second[i].size();
|
||||
if(w == 2 || w == 4 || w == 3 || w == 7){
|
||||
result++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cout << result << endl;
|
||||
|
||||
|
||||
|
||||
|
||||
cout << flush;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user