|
|
|
#define OLC_PGE_APPLICATION
|
|
|
|
#include "pixelGameEngine.h"
|
|
|
|
#include "olcutils.h"
|
|
|
|
#include "BigInt.h"
|
|
|
|
|
|
|
|
using namespace olc;
|
|
|
|
// C++ program to implement
|
|
|
|
// the above approach
|
|
|
|
|
|
|
|
struct Monkey{
|
|
|
|
std::vector<BigInt> items;
|
|
|
|
char operation;
|
|
|
|
int operation_amt;
|
|
|
|
int divisible;
|
|
|
|
int trueThrow;
|
|
|
|
int falseThrow;
|
|
|
|
int inspAmt;
|
|
|
|
};
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
std::vector<Monkey> monkeys;
|
|
|
|
std::ifstream file("input");
|
|
|
|
|
|
|
|
monkeys.push_back({{89,95,92,64,87,68},'*',11,2,7,4});
|
|
|
|
monkeys.push_back({{87,67},'+',1,13,3,6});
|
|
|
|
monkeys.push_back({{95, 79, 92, 82, 60},'+',6,3,1,6});
|
|
|
|
monkeys.push_back({{67, 97, 56},'*',-1,17,7,0});
|
|
|
|
monkeys.push_back({{80, 68, 87, 94, 61, 59, 50, 68},'*',7,19,5,2});
|
|
|
|
monkeys.push_back({{73, 51, 76, 59},'+',8,7,2,1});
|
|
|
|
monkeys.push_back({{92},'+',5,11,3,0});
|
|
|
|
monkeys.push_back({{99, 76, 78, 76, 79, 90, 89},'+',7,5,4,5});
|
|
|
|
|
|
|
|
for (int round=0;round<10000;round++){
|
|
|
|
for (int i=0;i<monkeys.size();i++){
|
|
|
|
Monkey&m=monkeys[i];
|
|
|
|
m.inspAmt+=m.items.size();
|
|
|
|
for (int j=0;j<m.items.size();j++){
|
|
|
|
BigInt worryLevel=m.items[j];
|
|
|
|
std::cout<<worryLevel<<std::endl;
|
|
|
|
if (m.operation=='+'){
|
|
|
|
if (m.operation_amt!=-1){
|
|
|
|
worryLevel+=m.operation_amt;
|
|
|
|
} else {
|
|
|
|
worryLevel*=2;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (m.operation_amt!=-1){
|
|
|
|
worryLevel*=m.operation_amt;
|
|
|
|
} else {
|
|
|
|
worryLevel*=worryLevel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//worryLevel/=3;
|
|
|
|
BigInt zero{"0"};
|
|
|
|
if (worryLevel%m.divisible==zero){
|
|
|
|
Monkey&newMonkey=monkeys[m.trueThrow];
|
|
|
|
newMonkey.items.push_back(worryLevel);
|
|
|
|
m.items.erase(m.items.begin());
|
|
|
|
j--;
|
|
|
|
} else {
|
|
|
|
Monkey&newMonkey=monkeys[m.falseThrow];
|
|
|
|
newMonkey.items.push_back(worryLevel);
|
|
|
|
m.items.erase(m.items.begin());
|
|
|
|
j--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::sort(monkeys.begin(),monkeys.end(),[](Monkey&first,Monkey&second){return second.inspAmt<first.inspAmt;});
|
|
|
|
for (int i=0;i<monkeys.size();i++){
|
|
|
|
Monkey&m=monkeys[i];
|
|
|
|
std::cout<<"Monkey "<<i<<": "<<m.inspAmt<<" inspections"<<std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cout<<(monkeys[0].inspAmt*monkeys[1].inspAmt)<<std::endl;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|