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