#include #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::size_t(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::ostream & out, std::string const& picture) { for (std::size_t y = 0; y < 6; y++) { for (std::size_t x = 0; x < 25; x++) { out << ('1' == picture[y*25+x] ? "▓" : "░"); } out << std::endl; } } } // namespace auto Main(std::istream & in, std::ostream & out) -> void { std::string line; std::getline(in, line); out << "Part 1: " << Part1(line) << std::endl; Draw(out, Flatten(line)); }