#ifndef INTCODE_HPP_ #define INTCODE_HPP_ #include #include #include #include #include #include template struct overloaded : Ts... { using Ts::operator()...; }; template overloaded(Ts...) -> overloaded; struct BadInstruction : public std::exception { std::int64_t instruction; explicit BadInstruction(std::int64_t instruction) : instruction{instruction} {} const char* what() const noexcept override { return "bad instruction"; } }; struct Input { std::int64_t& pos; }; struct Output { std::int64_t val; }; struct Halt {}; class intcode { std::vector rom_; std::unordered_map ram_; std::size_t pc_; std::size_t base_; auto ref(std::int64_t instruction, std::int64_t p, std::size_t offset) -> std::int64_t&; public: intcode(); intcode(std::vector ram); auto step() -> std::variant; auto at(std::size_t) -> std::int64_t&; }; auto parse_stream(std::istream& in) -> std::vector; #endif // INTCODE_HPP_