#pragma region Hidden Setup Stuff #define OLC_PGE_APPLICATION #include "olcPixelGameEngine.h" using namespace olc; enum Run{ FILE1, FILE2 }; // Override base class with your custom functionality class AoC2023 : public olc::PixelGameEngine { std::vectorlines; bool waitForRender=false; void wait(int pauseMs=0){ waitForRender=true; while(waitForRender); std::this_thread::sleep_for(std::chrono::milliseconds(pauseMs)); } #pragma endregion const int DAY = 8; Run runInput=FILE2; std::map>nodes; std::string instructions; struct Node{ std::string val; std::string startingNode; }; std::vector currentNodes; int instructionIndex=0; //133x133 vi2d lineStartNode; vi2d lineEndNode; bool drawInitialGrid=true; int path=0; void doStuff2(){ while(true){ //lines is accessible as a global. bool firstLine=true; for(int lineNumb=0;std::string&line:lines){ if(lineNumb==0){ instructions=line; }else if(lineNumb>=2){ std::string node=line.substr(0,3); nodes[node]={line.substr(line.find('(')+1,3),line.substr(line.find(')')-3,3)}; if(node[2]=='A'){ currentNodes.push_back({node,node}); } } lineNumb++; } wait(10000); long long step=0; bool notAtZ=true; while(notAtZ){ notAtZ=false; for(int counter=0;auto&[val,startingNode]:currentNodes){ char currentInstruction=instructions[instructionIndex]; int numb=0; for(int i=0;i<3;i++){ numb*=26; numb+=val[i]-'A'; } lineStartNode.x=(numb%133)*24+12; lineStartNode.y=(numb/133)*8; if(currentInstruction=='R'){ val=nodes[val].second; }else{ val=nodes[val].first; } if(val[2]!='Z'){ notAtZ=true; } numb=0; for(int i=0;i<3;i++){ numb*=26; numb+=val[i]-'A'; } lineEndNode.x=(numb%133)*24+12; lineEndNode.y=(numb/133)*8; path=counter; if(counter<7){ wait(0); } counter++; } instructionIndex=(instructionIndex+1)%instructions.length(); step++; } std::cout<=2){ nodes[line.substr(0,3)]={line.substr(line.find('(')+1,3),line.substr(line.find(')')-3,3)}; } lineNumb++; } int step=0; while(currentNode!="ZZZ"){ char currentInstruction=instructions[instructionIndex]; if(currentInstruction=='R'){ currentNode=nodes[currentNode].second; }else{ currentNode=nodes[currentNode].first; } instructionIndex=(instructionIndex+1)%instructions.length(); step++; } std::cout<colors{RED,BLUE,GREEN,YELLOW,MAGENTA,CYAN,WHITE}; SetPixelMode(Pixel::ALPHA); FillRect({0,0},GetScreenSize(),{0,0,0,1}); DrawLine(lineStartNode,lineEndNode,{colors[path%7].r,colors[path%7].g,colors[path%7].b,100},0xDDDDDDDD); } } #pragma region Hidden Engine Stuff public: AoC2023() { // Name your application std::string fileName="day"+std::to_string(DAY)+"_1.txt"; if(runInput==FILE2){fileName="day"+std::to_string(DAY)+"_2.txt";} std::ifstream file(fileName); while(file.good()){ std::string line; std::getline(file,line); lines.push_back(line); } sAppName = "Advent of Code 2023 - Day "+std::to_string(DAY); } public: bool OnUserCreate() override { return true; } bool OnUserUpdate(float fElapsedTime) override { static std::thread aocSolver(&AoC2023::doStuff2,this); if(waitForRender){ draw(); waitForRender=false; } return true; } }; int main() { AoC2023 game; if (game.Construct(3186, 1062, 2, 2)) game.Start(); return 0; } #pragma endregion