diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b04fe9..f09d81b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,4 +18,7 @@ add_executable(day07 day07.cpp) target_link_libraries(day07 intcode) add_executable(day09 day09.cpp) -target_link_libraries(day09 intcode) \ No newline at end of file +target_link_libraries(day09 intcode) + +add_executable(day11 day11.cpp) +target_link_libraries(day11 intcode) diff --git a/day07.cpp b/day07.cpp index ea9c230..fae588c 100644 --- a/day07.cpp +++ b/day07.cpp @@ -23,10 +23,10 @@ template auto Controller(Machine machine, R const ¶ms) { template auto Feed(R &&s, ValueType start) -> std::optional { for (auto &m : amps) { - auto i = m.step(); + auto i = m.Step(); if (auto p = std::get_if(&i)) { p->pos = start; - start = std::get(m.step()).val; + start = std::get(m.Step()).val; } else { return {}; } diff --git a/day11.cpp b/day11.cpp new file mode 100644 index 0000000..169f8f8 --- /dev/null +++ b/day11.cpp @@ -0,0 +1,56 @@ +#include +#include +#include +#include + +#include +using namespace intcode; + +namespace { + +using Coord = std::pair; + +auto Compute(Machine machine, ValueType start) + -> std::map { + + Coord here {0,0}; + std::map paint {{here,start}}; + ValueType dx = 1; + ValueType dy = 0; + + for (;;) { + auto effect = machine.Step(); + + if (std::holds_alternative(effect)) { + return paint; + } + + std::get(effect).pos = paint[here]; + auto color = std::get(machine.Step()).val; + auto dir = std::get(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 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)); +} diff --git a/lib/intcode.cpp b/lib/intcode.cpp index d98c30a..69ce176 100644 --- a/lib/intcode.cpp +++ b/lib/intcode.cpp @@ -103,7 +103,7 @@ auto ParseStream(std::istream &in) -> std::vector { std::string str; std::vector result; while (std::getline(in, str, ',')) { - result.push_back(std::stoi(str)); + result.push_back(std::stol(str)); } return result; }