Added older advents
This commit is contained in:
parent
8db2505049
commit
9cf858b860
78 changed files with 13807 additions and 0 deletions
59
advent_of_code_2019/day2/main1.cc
Normal file
59
advent_of_code_2019/day2/main1.cc
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
vector<int> read_input()
|
||||
{
|
||||
vector<int> rval;
|
||||
int buffer;
|
||||
char comma;
|
||||
|
||||
while (cin)
|
||||
{
|
||||
cin >> buffer;
|
||||
rval.push_back(buffer);
|
||||
cin >> comma;
|
||||
}
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
vector<int> program = read_input();
|
||||
size_t instruction = 0;
|
||||
|
||||
// fix according to assignment
|
||||
program[1] = 12;
|
||||
program[2] = 2;
|
||||
|
||||
while(true)
|
||||
{
|
||||
switch(program[instruction++])
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
size_t lhs = program[instruction++];
|
||||
size_t rhs = program[instruction++];
|
||||
size_t result = program[instruction++];
|
||||
program[result] = program[lhs] + program[rhs];
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
{
|
||||
size_t lhs = program[instruction++];
|
||||
size_t rhs = program[instruction++];
|
||||
size_t result = program[instruction++];
|
||||
program[result] = program[lhs] * program[rhs];
|
||||
}
|
||||
break;
|
||||
|
||||
case 99:
|
||||
cout << "Result: " << program[0] << "\n";
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue