Files
advent-of-code/2019/day_2/program_alarm.cc
2020-12-03 00:13:20 -03:00

48 lines
861 B
C++

#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include "intcode.hh"
std::vector<int> read_input_file() {
std::ifstream file("input");
std::vector<int> data;
std::string line;
while(std::getline(file, line, ','))
data.push_back(std::stoi(line));
return data;
}
void solve_a(std::vector<int> memory) {
memory[1] = 12;
memory[2] = 2;
auto vm = IntCode(memory);
std::cout << vm.get(0) << std::endl;
}
void solve_b(std::vector<int> memory) {
for(int x = 0; x < 99; x++){
for(int y = 0; y < 99; y++){
memory[1] = x;
memory[2] = y;
auto vm = IntCode(memory);
if(vm.get(0) == 19690720)
std::cout << x << ", " << y << " = " << (100 * x) + y << std::endl;
}
}
}
int main() {
auto memory = read_input_file();
solve_a(memory);
solve_b(memory);
return 0;
}