Implement day 19 part 1.

This commit is contained in:
2019-12-19 20:24:34 +01:00
parent 7116979d62
commit 73898e1cb7
2 changed files with 50 additions and 1 deletions

View File

@@ -1,8 +1,56 @@
#include <iostream>
#include <cassert>
#include "days.hpp"
#include "utils.hpp"
namespace {
bool bounds_check(aoc2019::IntCodeComputer computer, std::int64_t x, std::int64_t y) {
std::deque<std::int64_t> output_buffer;
computer.connectOutput(output_buffer);
computer.sendInput(x);
computer.sendInput(y);
computer.run();
assert(computer.isTerminated());
assert(!output_buffer.empty());
return output_buffer.front();
}
}
void aoc2019::day19_part1(std::istream &input, std::ostream &output) {
output << "Not implemented\n";
IntCodeComputer computer(input);
std::int64_t covered = 0;
int last_width = 1;
int last_start = 0;
for (std::int64_t y = 0; y < 50; ++y) {
auto x = last_start;
while (!bounds_check(computer, x, y) && x < 50) {
++x;
}
if (x == 50) break;
last_start = x;
x += last_width - 1;
if (!bounds_check(computer, x, y)) {
std::cerr << x << "," << y << "," << covered << std::endl;
throw std::logic_error("Assumption false");
}
while (bounds_check(computer, x, y) && x < 50) {
++x;
}
last_width = x - last_start;
covered += last_width;
}
output << covered << std::endl;
}
void aoc2019::day19_part2(std::istream &input, std::ostream &output) {