stash
This commit is contained in:
parent
898ae0521b
commit
005bd76e6b
|
@ -19,3 +19,6 @@ target_link_libraries(day07 intcode)
|
|||
|
||||
add_executable(day09 day09.cpp)
|
||||
target_link_libraries(day09 intcode)
|
||||
|
||||
add_executable(day11 day11.cpp)
|
||||
target_link_libraries(day11 intcode)
|
||||
|
|
|
@ -23,10 +23,10 @@ template <class R> auto Controller(Machine machine, R const ¶ms) {
|
|||
template <class R>
|
||||
auto Feed(R &&s, 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
56
day11.cpp
Normal 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));
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user