Added older advents

This commit is contained in:
Jos van Goor 2022-12-01 13:46:47 +01:00
parent 8db2505049
commit 9cf858b860
78 changed files with 13807 additions and 0 deletions

View 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;
}
}
}