mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Implement day 8.
This commit is contained in:
1
2019/inputs/07.txt
Normal file
1
2019/inputs/07.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
3,8,1001,8,10,8,105,1,0,0,21,46,67,76,97,118,199,280,361,442,99999,3,9,1002,9,3,9,101,4,9,9,102,3,9,9,1001,9,3,9,1002,9,2,9,4,9,99,3,9,102,2,9,9,101,5,9,9,1002,9,2,9,101,2,9,9,4,9,99,3,9,101,4,9,9,4,9,99,3,9,1001,9,4,9,102,2,9,9,1001,9,4,9,1002,9,5,9,4,9,99,3,9,102,3,9,9,1001,9,2,9,1002,9,3,9,1001,9,3,9,4,9,99,3,9,101,1,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,1,9,4,9,3,9,1001,9,1,9,4,9,3,9,101,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,101,1,9,9,4,9,99,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,1,9,4,9,3,9,102,2,9,9,4,9,3,9,101,1,9,9,4,9,3,9,101,2,9,9,4,9,99,3,9,1002,9,2,9,4,9,3,9,1001,9,1,9,4,9,3,9,101,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,1002,9,2,9,4,9,3,9,101,1,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,1,9,4,9,99,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,101,1,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1001,9,1,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,1,9,4,9,99,3,9,1002,9,2,9,4,9,3,9,101,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,101,1,9,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,99
|
||||||
1
2019/inputs/08.txt
Normal file
1
2019/inputs/08.txt
Normal file
File diff suppressed because one or more lines are too long
@@ -1,6 +1,6 @@
|
|||||||
|
#include <algorithm>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
|
||||||
#include "days.hpp"
|
#include "days.hpp"
|
||||||
#include "utils.hpp"
|
#include "utils.hpp"
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,69 @@
|
|||||||
|
#include <algorithm>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <limits>
|
||||||
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
#include "days.hpp"
|
#include "days.hpp"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
constexpr std::size_t WIDTH = 25;
|
||||||
|
constexpr std::size_t HEIGHT = 6;
|
||||||
|
constexpr std::size_t TILE_SIZE = WIDTH * HEIGHT;
|
||||||
|
|
||||||
|
enum Color {
|
||||||
|
BLACK = '0',
|
||||||
|
WHITE = '1',
|
||||||
|
TRANSPARENT = '2',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void aoc2019::day08_part1(std::istream &input, std::ostream &output) {
|
void aoc2019::day08_part1(std::istream &input, std::ostream &output) {
|
||||||
output << "Not implemented\n";
|
std::string buffer;
|
||||||
|
std::getline(input, buffer);
|
||||||
|
|
||||||
|
std::string_view image = buffer;
|
||||||
|
auto best = std::numeric_limits<int>::max();
|
||||||
|
auto best_score = 0;
|
||||||
|
|
||||||
|
for (std::size_t i = 0; i < buffer.length(); i += TILE_SIZE) {
|
||||||
|
auto tile = image.substr(i, TILE_SIZE);
|
||||||
|
|
||||||
|
auto zeros = std::count(tile.begin(), tile.end(), '0');
|
||||||
|
|
||||||
|
if (zeros < best) {
|
||||||
|
best = zeros;
|
||||||
|
|
||||||
|
best_score = std::count(tile.begin(), tile.end(), '1') * std::count(tile.begin(), tile.end(), '2');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
output << best_score << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void aoc2019::day08_part2(std::istream &input, std::ostream &output) {
|
void aoc2019::day08_part2(std::istream &input, std::ostream &output) {
|
||||||
output << "Not implemented\n";
|
std::string buffer;
|
||||||
|
std::getline(input, buffer);
|
||||||
|
|
||||||
|
std::string_view image = buffer;
|
||||||
|
|
||||||
|
std::array<Color, TILE_SIZE> final_image;
|
||||||
|
std::fill(final_image.begin(), final_image.end(), TRANSPARENT);
|
||||||
|
|
||||||
|
for (std::size_t i = 0; i < buffer.length(); i += TILE_SIZE) {
|
||||||
|
auto tile = image.substr(i, TILE_SIZE);
|
||||||
|
|
||||||
|
for (int j = 0; j < TILE_SIZE; ++j) {
|
||||||
|
if (final_image[j] == TRANSPARENT) {
|
||||||
|
final_image[j] = static_cast<Color>(tile[j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (std::size_t i = 0; i < final_image.size(); ++i) {
|
||||||
|
output << (final_image[i] == WHITE ? '#' : ' ');
|
||||||
|
if (i % WIDTH == WIDTH - 1) {
|
||||||
|
output << '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user