From 0bf0d4120ec299db8b83a6e5f8adc8eacc18c012 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Fri, 8 Dec 2023 13:20:04 -0600 Subject: [PATCH] Day 8 Part 2 apparently! Just took forever. :P --- Day 8/Day 8.vcxproj | 6 ++++++ Day 8/day8_1.txt | 17 ++++++++------- Day 8/main.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 63 insertions(+), 11 deletions(-) diff --git a/Day 8/Day 8.vcxproj b/Day 8/Day 8.vcxproj index 2b8dabb..7648a4e 100644 --- a/Day 8/Day 8.vcxproj +++ b/Day 8/Day 8.vcxproj @@ -70,6 +70,12 @@ + + $(ProjectName)3 + + + $(ProjectName)3 + Level3 diff --git a/Day 8/day8_1.txt b/Day 8/day8_1.txt index 59e2d47..a8e2c98 100644 --- a/Day 8/day8_1.txt +++ b/Day 8/day8_1.txt @@ -1,9 +1,10 @@ -RL +LR -AAA = (BBB, CCC) -BBB = (DDD, EEE) -CCC = (ZZZ, GGG) -DDD = (DDD, DDD) -EEE = (EEE, EEE) -GGG = (GGG, GGG) -ZZZ = (ZZZ, ZZZ) \ No newline at end of file +11A = (11B, XXX) +11B = (XXX, 11Z) +11Z = (11B, XXX) +22A = (22B, XXX) +22B = (22C, 22C) +22C = (22Z, 22Z) +22Z = (22B, 22B) +XXX = (XXX, XXX) \ No newline at end of file diff --git a/Day 8/main.cpp b/Day 8/main.cpp index f5114e3..42c02b7 100644 --- a/Day 8/main.cpp +++ b/Day 8/main.cpp @@ -30,9 +30,54 @@ std::map>nodes; std::string instructions; -std::string currentNode="AAA"; +struct Node{ + std::string val; + std::string startingNode; +}; + +std::vector 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<