19
This commit is contained in:
52
2019/19.cpp
Normal file
52
2019/19.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#include <iostream>
|
||||
|
||||
#include <aocpp/Coord.hpp>
|
||||
#include <aocpp/Startup.hpp>
|
||||
#include <intcode/intcode.hpp>
|
||||
|
||||
using namespace aocpp;
|
||||
using namespace intcode;
|
||||
|
||||
namespace {
|
||||
|
||||
class Scanner {
|
||||
Machine machine_;
|
||||
|
||||
public:
|
||||
Scanner(Machine machine) : machine_{std::move(machine)} {}
|
||||
|
||||
auto operator()(ValueType x, ValueType y) const -> bool {
|
||||
Machine m {machine_};
|
||||
StepInput(m, x);
|
||||
StepInput(m, y);
|
||||
return StepOutput(m);
|
||||
}
|
||||
};
|
||||
|
||||
auto Part1(Scanner const& scanner) {
|
||||
std::int64_t count {};
|
||||
for (std::int64_t y = 0; y < 50; y++) {
|
||||
for (std::int64_t x = 0; x < 50; x++) {
|
||||
if (scanner(x, y)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
auto Part2(Scanner const& scanner) {
|
||||
ValueType x = 0;
|
||||
for(ValueType y = 99;; y++){
|
||||
for (; !scanner(x, y); x++);
|
||||
if (scanner(x+99,y-99)) { return 10000 * x + y-99; }
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
auto main(int argc, char** argv) -> int {
|
||||
auto scanner = Scanner{Machine{ParseStream(aocpp::Startup(argc, argv))}};
|
||||
std::cout << "Part 1: " << Part1(scanner) << std::endl;
|
||||
std::cout << "Part 2: " << Part2(scanner) << std::endl;
|
||||
}
|
@@ -49,6 +49,9 @@ target_link_libraries(17 aocpp intcode)
|
||||
add_executable(18 18.cpp)
|
||||
target_link_libraries(18 aocpp)
|
||||
|
||||
add_executable(19 19.cpp)
|
||||
target_link_libraries(19 aocpp intcode)
|
||||
|
||||
add_executable(20 20.cpp)
|
||||
target_link_libraries(20 aocpp)
|
||||
|
||||
|
Reference in New Issue
Block a user