66 lines
1.4 KiB
C++
66 lines
1.4 KiB
C++
#include <algorithm>
|
|
#include <cstdint>
|
|
#include <array>
|
|
#include <iostream>
|
|
#include <iterator>
|
|
#include <vector>
|
|
#include <string_view>
|
|
#include <numeric>
|
|
|
|
#include <aocpp/Startup.hpp>
|
|
|
|
namespace {
|
|
|
|
auto Part1(std::string const& line) {
|
|
std::size_t part1 = 0;
|
|
auto seen = std::numeric_limits<std::size_t>::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));
|
|
}
|