Estoy intentando hacer años anteriores
This commit is contained in:
47
2019/day_2/program_alarm.cc
Normal file
47
2019/day_2/program_alarm.cc
Normal file
@@ -0,0 +1,47 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user