|
|
|
@ -30,9 +30,54 @@ std::map<std::string,std::pair<std::string,std::string>>nodes; |
|
|
|
|
|
|
|
|
|
std::string instructions; |
|
|
|
|
|
|
|
|
|
std::string currentNode="AAA"; |
|
|
|
|
struct Node{ |
|
|
|
|
std::string val; |
|
|
|
|
std::string startingNode; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
std::vector<Node> currentNodes; |
|
|
|
|
int instructionIndex=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++; |
|
|
|
|
} |
|
|
|
|
long long step=0; |
|
|
|
|
bool notAtZ=true; |
|
|
|
|
while(notAtZ){ |
|
|
|
|
notAtZ=false; |
|
|
|
|
for(auto&[val,startingNode]:currentNodes){ |
|
|
|
|
char currentInstruction=instructions[instructionIndex]; |
|
|
|
|
if(currentInstruction=='R'){ |
|
|
|
|
val=nodes[val].second; |
|
|
|
|
}else{ |
|
|
|
|
val=nodes[val].first; |
|
|
|
|
} |
|
|
|
|
if(val[2]!='Z'){ |
|
|
|
|
notAtZ=true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
instructionIndex=(instructionIndex+1)%instructions.length(); |
|
|
|
|
step++; |
|
|
|
|
} |
|
|
|
|
std::cout<<step<<std::endl; |
|
|
|
|
break; |
|
|
|
|
//wait(0); //Wait for 0ms and render the screen (calls draw())
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
/*
|
|
|
|
|
void doStuff(){ |
|
|
|
|
while(true){ //lines is accessible as a global.
|
|
|
|
|
bool firstLine=true; |
|
|
|
@ -61,7 +106,7 @@ void doStuff(){ |
|
|
|
|
//wait(0); //Wait for 0ms and render the screen (calls draw())
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
|
|
|
void draw(){ //Only use Sprites! If using decals, you must reference global variables!
|
|
|
|
|
Clear(BLACK); |
|
|
|
|
int count=0; |
|
|
|
@ -97,7 +142,7 @@ public: |
|
|
|
|
|
|
|
|
|
bool OnUserUpdate(float fElapsedTime) override |
|
|
|
|
{ |
|
|
|
|
static std::thread aocSolver(&AoC2023::doStuff,this); |
|
|
|
|
static std::thread aocSolver(&AoC2023::doStuff2,this); |
|
|
|
|
|
|
|
|
|
if(waitForRender){ |
|
|
|
|
draw(); |
|
|
|
|