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 @@
1,0,0,3,1,1,2,3,1,3,4,3,1,5,0,3,2,1,10,19,1,19,5,23,1,6,23,27,1,27,5,31,2,31,10,35,2,35,6,39,1,39,5,43,2,43,9,47,1,47,6,51,1,13,51,55,2,9,55,59,1,59,13,63,1,6,63,67,2,67,10,71,1,9,71,75,2,75,6,79,1,79,5,83,1,83,5,87,2,9,87,91,2,9,91,95,1,95,10,99,1,9,99,103,2,103,6,107,2,9,107,111,1,111,5,115,2,6,115,119,1,5,119,123,1,123,2,127,1,127,9,0,99,2,0,14,0

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

View file

@ -0,0 +1,79 @@
#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 run_program(vector<int> program, int noun = 12, int verb = 2)
{
cout << "running program!\n";
size_t instruction = 0;
program[1] = noun;
program[2] = verb;
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:
return program[0];
}
}
}
int main(int argc, char *argv[])
{
vector<int> program = read_input();
int target_output = 19690720;
for (int noun = 0; noun < 100; ++noun)
{
cout << "\rIteration: " << noun << " / 100";
for (int verb = 0; verb < 100; ++verb)
{
int result = run_program(program, noun, verb);
if (result == target_output)
{
cout << "Noun: " << noun << "\n";
cout << "Verb: " << verb << "\n";
cout << "Answer: " << (100 * noun + verb) << "\n";
return 0;
}
}
}
}

View file

@ -0,0 +1 @@
2,3,0,3,99