diff --git a/C++ProjectTemplate b/C++ProjectTemplate index 5614f2b..39102d1 100755 Binary files a/C++ProjectTemplate and b/C++ProjectTemplate differ diff --git a/main.cpp b/main.cpp index 2359c65..533bdf4 100644 --- a/main.cpp +++ b/main.cpp @@ -61,6 +61,7 @@ void explore(std::string currentRoom,std::mapvisitedvalves,int } if (flowTotal>maxFlow){ maxFlow=flowTotal; + std::cout<<"New max found: "<visitedvalves,int int main() { - std::ifstream file("testinput"); + std::ifstream file("input"); while (file.good()){ std::string line; std::getline(file,line); @@ -115,19 +116,30 @@ int main() std::cout<::iterator it=rooms.begin();it!=rooms.end();++it){ for (std::map::iterator it2=rooms.begin();it2!=rooms.end();++it2){ if (it->first==it2->first){ rooms[it->first].paths[it2->first]=0; - std::cout<first<<"->"<first<<": 0"<first<<"->"<first<<": 0"<first].paths[it2->first]=findRoute(it->first,it2->first,{},0); - std::cout<first<<"->"<first<<": "<first].paths[it2->first]<first<<"->"<first<<": "<first].paths[it2->first]<::iterator it=rooms.begin();it!=rooms.end();++it){ + int j=0; + for (std::map::iterator it2=rooms.begin();it2!=rooms.end();++it2){ + if (j>=i){ + + } + } + i++; + } + return 0; } diff --git a/part1 b/part1 new file mode 100644 index 0000000..9222a5a --- /dev/null +++ b/part1 @@ -0,0 +1,134 @@ +#define OLC_PGE_APPLICATION +#include "pixelGameEngine.h" +#include "olcutils.h" + +using namespace olc; + +struct Room{ + std::vectorconnections; + std::mappaths; + int flowValue=0; + std::string name=""; + friend std::ostream&operator<<(std::ostream&out,Room&rhs){ + out<<"Valve "<rooms; +int maxFlow=0; +int iterations=0; +int branchesRemaining=0; + +int findRoute(std::string start,std::string end,std::mapvisited,int dist){ + visited[start]=true; + int distance=INFINITY; + Room r=rooms[start]; + for (int i=0;ivisitedvalves,int flowRate,int minute,int flowTotal,std::string journey,std::string flowTotals){ + + //std::cout<<"Exploring "<maxFlow){ + maxFlow=flowTotal; + std::cout<<"New max found: "<::iterator it=rooms.begin();it!=rooms.end();++it){ + if (visitedvalves.find(it->first)==visitedvalves.end()&&rooms[it->first].flowValue>0){ + //We haven't tried going here yet. + if (minute+rooms[currentRoom].paths[it->first]<30){ + for (int i=0;ifirst];i++){ + flowTotal+=flowRate; + flowTotals+="->"+std::to_string(flowTotal); + } + explore(it->first,visitedvalves,flowRate,minute+rooms[currentRoom].paths[it->first],flowTotal,journey+"->"+it->first,flowTotals); + flowTotal+=flowRate; + flowTotals+="->"+std::to_string(flowTotal); + explore(it->first,visitedvalves,flowRate+rooms[it->first].flowValue,minute+rooms[currentRoom].paths[it->first]+1,flowTotal,journey+"->"+it->first,flowTotals); + flowTotal=previousFlowTotal; + flowTotals=prevFlowTotal; + } + } + } +} + +int main() +{ + std::ifstream file("input"); + while (file.good()){ + std::string line; + std::getline(file,line); + std::cout<0){ + int flowRate=std::atoi(line.substr(line.find('=')+1,line.find(';')-line.find('=')-1).c_str()); + std::cout<<"Flow Rate: "<::iterator it=rooms.begin();it!=rooms.end();++it){ + for (std::map::iterator it2=rooms.begin();it2!=rooms.end();++it2){ + if (it->first==it2->first){ + rooms[it->first].paths[it2->first]=0; + std::cout<first<<"->"<first<<": 0"<first].paths[it2->first]=findRoute(it->first,it2->first,{},0); + std::cout<first<<"->"<first<<": "<first].paths[it2->first]<