Implement day 13 part 1.

This commit is contained in:
2019-12-13 07:20:59 +01:00
parent 09a0a9513b
commit 98f790242c
2 changed files with 32 additions and 1 deletions

1
2019/inputs/13.txt Normal file

File diff suppressed because one or more lines are too long

View File

@@ -1,8 +1,38 @@
#include <iostream>
#include "days.hpp"
#include "utils.hpp"
#include "point.hpp"
namespace {
typedef aoc2019::Point<int64_t, 2> point_t;
enum class Tile {
EMPTY,
WALL,
BLOCK,
PADDLE,
BALL,
};
}
void aoc2019::day13_part1(std::istream &input, std::ostream &output) {
output << "Not implemented\n";
aoc2019::IntCodeComputer computer(aoc2019::IntCodeComputer::read_intcode(input));
std::deque<std::int64_t> output_buffer;
computer.connectOutput(output_buffer);
computer.run();
std::unordered_map<point_t, Tile> drawn;
while (!output_buffer.empty()) {
auto x = output_buffer.front(); output_buffer.pop_front();
auto y = output_buffer.front(); output_buffer.pop_front();
auto type = output_buffer.front(); output_buffer.pop_front();
drawn[{x, y}] = static_cast<Tile>(type);
}
output << std::count_if(drawn.begin(), drawn.end(), [](const auto& x) { return x.second == Tile::BLOCK; })<< std::endl;
}
void aoc2019::day13_part2(std::istream &input, std::ostream &output) {