#ifndef INTCODE_H #define INTCODE_H #include #include class IntCode { std::vector memory; bool halt = false; int ip = 0; //instruction pointer void op_add() { int param_1 = memory[memory[ip+1]]; int param_2 = memory[memory[ip+2]]; memory[memory[ip+3]] = param_1 + param_2; ip += 4; } void op_mult() { int param_1 = memory[memory[ip+1]]; int param_2 = memory[memory[ip+2]]; memory[memory[ip+3]] = param_1 * param_2; ip += 4; } void run() { while(!halt){ switch(memory[ip]) { case 1: op_add(); break; case 2: op_mult(); break; case 99: halt = true; break; } } } public: IntCode(std::vector memory) { this->memory = memory; run(); } int get(int address) { return memory[address]; } }; #endif