You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
AoC2022_Day10/part1

55 lines
1.3 KiB

#define OLC_PGE_APPLICATION
#include "pixelGameEngine.h"
#include "olcutils.h"
using namespace olc;
void incrementClock(int&clockCycle,int&reg,int&sum){
clockCycle++;
if (clockCycle==20||
clockCycle==60||
clockCycle==100||
clockCycle==140||
clockCycle==180||
clockCycle==220){
sum+=clockCycle*reg;
}
}
int main()
{
std::ifstream file("input");
int clockCycle=0;
bool noop=true;
int reg=1;
int amtToAdd=0;
int sum=0;
while (file.good()){
std::string line;
std::getline(file,line);
if (line.length()>0){
std::string command=line.substr(0,line.find(' '));
if (command=="noop"){
noop=true;
//std::cout<<"noop"<<std::endl;
} else {
int amt=std::atoi(line.substr(line.find(' ')+1,std::string::npos).c_str());
//std::cout<<amt<<std::endl;
amtToAdd=amt;
noop=false;
}
if (noop){
incrementClock(clockCycle,reg,sum);
} else {
for (int i=0;i<2;i++){
incrementClock(clockCycle,reg,sum);
}
reg+=amtToAdd;
}
}
std::cout<<line<<std::endl;
}
std::cout<<"Sum: "<<sum<<std::endl;
return 0;
}