#include #include #include #include #include #include #include #include namespace { auto Part1(std::string const& line) { std::size_t part1 = 0; auto seen = std::numeric_limits::max(); for (auto it = line.begin(); std::distance(it, line.end()) >= 150; std::advance(it, 150)) { auto zeros = std::count(it, it + 150, '0'); if (zeros < seen) { seen = zeros; part1 = std::count(it, it + 150, '1') * std::count(it, it + 150, '2'); } } return part1; } auto Flatten(std::string const& line) { std::string merged(150, ' '); for (std::size_t i = 0; i < 150; i++) { for (auto it = line.begin(); std::distance(it, line.end()) >= 150; std::advance(it, 150)) { if ('2' != it[i]) { merged[i] = it[i]; break; } } } return merged; } auto Draw(std::string const& picture) { for (std::size_t y = 0; y < 6; y++) { for (std::size_t x = 0; x < 25; x++) { std::cout << ('1' == picture[y*25+x] ? "▓" : "░"); } std::cout << std::endl; } } } // namespace auto main(int argc, char** argv) -> int { std::string line; std::getline(aocpp::Startup(argc, argv), line); std::cout << "Part 1: " << Part1(line) << std::endl; Draw(Flatten(line)); }