-
Notifications
You must be signed in to change notification settings - Fork 142
/
Copy pathd2.cpp
53 lines (48 loc) · 929 Bytes
/
d2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <fstream>
#include <iostream>
#include <vector>
using namespace std;
int run(vector<int> program) {
vector<int> arr = program;
auto i = 0;
while (true) {
auto op = arr[i];
if (op == 99) {
return arr[0];
}
auto a = arr[i + 1];
auto b = arr[i + 2];
auto to = arr[i + 3];
if (op == 1) {
arr[to] = arr[a] + arr[b];
} else if (op == 2) {
arr[to] = arr[a] * arr[b];
}
i += 4;
}
}
int main() {
ifstream ifile("./input.txt");
vector<int> program;
while (ifile) {
char c;
int i;
ifile >> i >> c;
program.push_back(i);
}
vector<int> p1 = program;
p1[1] = 12;
p1[2] = 2;
cout << run(p1) << "\n";
for (int x = 0; x < 100; ++x) {
for (int y = 0; y < 100; ++y) {
vector<int> p2 = program;
p2[1] = x;
p2[2] = y;
if (run(p2) == 19690720) {
cout << x*100+y << "\n";
}
}
}
return 0;
}