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/main.cpp

58 lines
1.4 KiB

2 years ago
#define OLC_PGE_APPLICATION
#include "pixelGameEngine.h"
#include "olcutils.h"
using namespace olc;
void incrementClock(int&clockCycle,int&reg,int&sum){
if (clockCycle%40>=reg-1&&clockCycle%40<=reg+1){
std::cout<<'#';
} else {
std::cout<<'.';
}
clockCycle++;
if (clockCycle%40==0){
std::cout<<std::endl;
2 years ago
}
}
2 years ago
int main()
{
std::ifstream file("input");
int clockCycle=0;
bool noop=true;
int reg=1;
int amtToAdd=0;
int sum=0;
int crt=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;
2 years ago
return 0;
}