#include #include #include #include #include #include #include using namespace std; auto read_file(string_view filename) { fstream input{ filename }; return vector{ istream_iterator{ input }, istream_iterator{} }; } auto to_int(string_view str) { auto result = 0U; for ( auto chr: str ) { result <<= 1U; if ( chr == 'B' || chr == 'R' ) { result |= 1U; } } return result; } void part1(const vector& lines) { auto value = 0U; for ( const auto& line: lines ) { value = max(value, to_int(line)); } cout << value << endl; } void part2(const vector& lines) { vector values; transform(lines.begin(), lines.end(), back_inserter(values), to_int); sort(values.begin(), values.end()); for ( size_t idx = 1; idx != values.size(); ++idx ) { if ( values[idx - 1] != values[idx] - 1 ) { cout << values[idx] - 1 << endl; break; } } } int main() { auto lines = read_file("data/day05.txt"); part1(lines); part2(lines); }