64 lines
1.4 KiB
C++
64 lines
1.4 KiB
C++
#include <algorithm>
|
|
#include <cstdint>
|
|
#include <array>
|
|
#include <iostream>
|
|
#include <iterator>
|
|
#include <vector>
|
|
#include <string_view>
|
|
|
|
#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::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));
|
|
}
|