// Solutions to the Advent Of Code 2024. // Copyright (C) 2025 Stefan Müller // // This program is free software: you can redistribute it and/or modify it under // the terms of the GNU General Public License as published by the Free Software // Foundation, either version 3 of the License, or (at your option) any later // version. // // This program is distributed in the hope that it will be useful, but WITHOUT // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along with // this program. If not, see . #pragma once #include #include #include #include class ChronospatialComputerInstruction { public: ChronospatialComputerInstruction(const ChronospatialComputerOperandType type); virtual ~ChronospatialComputerInstruction() = default; void run(ChronospatialComputerState& state, const int operand) const; protected: virtual void runValue(ChronospatialComputerState& state, const int operandValue) const = 0; private: std::function&, const int)> operandFunctor_; }; #pragma region ChronospatialComputerDivisionInstruction // Represents instruction "adv" (opcode 0), "bdv" (opcode 6), or "cdv" (opcode 7). class ChronospatialComputerDivisionInstruction : public ChronospatialComputerInstruction { public: ChronospatialComputerDivisionInstruction(const size_t destination); protected: virtual void runValue(ChronospatialComputerState& state, const int operandValue) const override; private: size_t destination_; }; #pragma endregion #pragma region ChronospatialComputerXorLiteralInstruction // Represents instruction "bxl" (opcode 1). class ChronospatialComputerXorLiteralInstruction : public ChronospatialComputerInstruction { public: ChronospatialComputerXorLiteralInstruction(); protected: virtual void runValue(ChronospatialComputerState& state, const int operandValue) const override; }; #pragma endregion #pragma region ChronospatialComputerModuloInstruction // Represents instruction "bst" (opcode 2). class ChronospatialComputerModuloInstruction : public ChronospatialComputerInstruction { public: ChronospatialComputerModuloInstruction(); protected: virtual void runValue(ChronospatialComputerState& state, const int operandValue) const override; }; #pragma endregion #pragma region ChronospatialComputerJumpInstruction // Represents instruction "jnz" (opcode 3). class ChronospatialComputerJumpInstruction : public ChronospatialComputerInstruction { public: ChronospatialComputerJumpInstruction(); protected: virtual void runValue(ChronospatialComputerState& state, const int operandValue) const override; }; #pragma endregion #pragma region ChronospatialComputerXorRegisterInstruction // Represents instruction "bxc" (opcode 4). class ChronospatialComputerXorRegisterInstruction : public ChronospatialComputerInstruction { public: ChronospatialComputerXorRegisterInstruction(); protected: virtual void runValue(ChronospatialComputerState& state, const int operandValue) const override; }; #pragma endregion #pragma region ChronospatialComputerOutInstruction // Represents instruction "out" (opcode 5). class ChronospatialComputerOutInstruction : public ChronospatialComputerInstruction { public: ChronospatialComputerOutInstruction(); protected: virtual void runValue(ChronospatialComputerState& state, const int operandValue) const override; }; #pragma endregion