This commit is contained in:
Eric Mertens 2022-11-03 19:49:07 -07:00
parent 898ae0521b
commit 005bd76e6b
4 changed files with 63 additions and 4 deletions

View File

@ -18,4 +18,7 @@ add_executable(day07 day07.cpp)
target_link_libraries(day07 intcode)
add_executable(day09 day09.cpp)
target_link_libraries(day09 intcode)
target_link_libraries(day09 intcode)
add_executable(day11 day11.cpp)
target_link_libraries(day11 intcode)

View File

@ -23,10 +23,10 @@ template <class R> auto Controller(Machine machine, R const &params) {
template <class R>
auto Feed(R &&amps, ValueType start) -> std::optional<ValueType> {
for (auto &m : amps) {
auto i = m.step();
auto i = m.Step();
if (auto p = std::get_if<Input>(&i)) {
p->pos = start;
start = std::get<Output>(m.step()).val;
start = std::get<Output>(m.Step()).val;
} else {
return {};
}

56
day11.cpp Normal file
View File

@ -0,0 +1,56 @@
#include <iostream>
#include <utility>
#include <tuple>
#include <map>
#include <intcode.hpp>
using namespace intcode;
namespace {
using Coord = std::pair<ValueType, ValueType>;
auto Compute(Machine machine, ValueType start)
-> std::map<Coord, ValueType> {
Coord here {0,0};
std::map<Coord, ValueType> paint {{here,start}};
ValueType dx = 1;
ValueType dy = 0;
for (;;) {
auto effect = machine.Step();
if (std::holds_alternative<Halt>(effect)) {
return paint;
}
std::get<Input>(effect).pos = paint[here];
auto color = std::get<Output>(machine.Step()).val;
auto dir = std::get<Output>(machine.Step()).val;
paint[here] = color;
std::swap(dx, dy);
if (dir) {
dx = -dx;
} else {
dy = -dy;
}
here.first += dx;
here.second += dy;
}
}
auto Draw(std::map<Coord, ValueType> image) {
ValueType minX = 1000, maxX = -1000, minY = 1000, maxY = -1000;
}
} // namespace
auto main() -> int {
auto machine = Machine{ParseStream(std::cin)};
std::cout << "Part 1: " << Compute(machine, 0).size() << std::endl;
Draw(Compute(std::move(machine), 1));
}

View File

@ -103,7 +103,7 @@ auto ParseStream(std::istream &in) -> std::vector<ValueType> {
std::string str;
std::vector<ValueType> result;
while (std::getline(in, str, ',')) {
result.push_back(std::stoi(str));
result.push_back(std::stol(str));
}
return result;
}