Day 8 Part 2 apparently! Just took forever. :P

master
sigonasr2 1 year ago
parent 7fe246e3f3
commit 0bf0d4120e
  1. 6
      Day 8/Day 8.vcxproj
  2. 17
      Day 8/day8_1.txt
  3. 51
      Day 8/main.cpp

@ -70,6 +70,12 @@
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup> </ImportGroup>
<PropertyGroup Label="UserMacros" /> <PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<TargetName>$(ProjectName)3</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<TargetName>$(ProjectName)3</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile> <ClCompile>
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>

@ -1,9 +1,10 @@
RL LR
AAA = (BBB, CCC) 11A = (11B, XXX)
BBB = (DDD, EEE) 11B = (XXX, 11Z)
CCC = (ZZZ, GGG) 11Z = (11B, XXX)
DDD = (DDD, DDD) 22A = (22B, XXX)
EEE = (EEE, EEE) 22B = (22C, 22C)
GGG = (GGG, GGG) 22C = (22Z, 22Z)
ZZZ = (ZZZ, ZZZ) 22Z = (22B, 22B)
XXX = (XXX, XXX)

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

Loading…
Cancel
Save