Completed Part 2

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent 55a95a3a08
commit fb228c81d8
  1. BIN
      C++ProjectTemplate
  2. 90
      main.cpp
  3. 232262
      out

Binary file not shown.

@ -30,11 +30,13 @@ int maxFlow=0;
int iterations=0; int iterations=0;
int branchesRemaining=0; int branchesRemaining=0;
void printArr(int n){ void printArr(){
int minutesRemaining1=26; int minutesRemaining1=26;
int minutesRemaining2=26; int minutesRemaining2=26;
std::string currentPos="AA"; std::string currentPos="AA";
std::string path1="AA";
std::string currentPos2="AA"; std::string currentPos2="AA";
std::string path2="AA";
std::vector<std::string> movePlan1; std::vector<std::string> movePlan1;
std::vector<std::string> movePlan2; std::vector<std::string> movePlan2;
int moveAmt1=0; //How many steps left to move. int moveAmt1=0; //How many steps left to move.
@ -44,7 +46,7 @@ void printArr(int n){
int flowRate=0; int flowRate=0;
int flowTotal=0; int flowTotal=0;
for (int i=0;i<n;i++){ for (int i=0;i<targetRooms.size();i++){
std::string valve=targetRooms[i]; std::string valve=targetRooms[i];
if (i&1){ if (i&1){
movePlan2.push_back(valve); movePlan2.push_back(valve);
@ -54,45 +56,83 @@ void printArr(int n){
//std::cout<<a[i]<<" "; //std::cout<<a[i]<<" ";
} }
moveAmt1=rooms[currentPos].paths[movePlan1[currentMarker1]]; moveAmt1=rooms[currentPos].paths[movePlan1[currentMarker1]];
moveAmt2=rooms[currentPos2].paths[movePlan1[currentMarker2]]; moveAmt2=rooms[currentPos2].paths[movePlan2[currentMarker2]];
std::cout<<"Current Position 1:"<<currentPos<<std::endl;
std::cout<<"Current Position 2:"<<currentPos2<<std::endl;
std::cout<<" Flow Total:"<<flowTotal<<std::endl;
for (int i=0;i<26;i++){ for (int i=0;i<26;i++){
std::cout<<"Minute "<<i+1<<std::endl;
flowTotal+=flowRate; flowTotal+=flowRate;
if (moveAmt1==0){ std::cout<<" Flow: "<<flowTotal<<std::endl;
//We open the valve. Then move to the next one. std::cout<<" Flow Rate: "<<flowRate<<std::endl;
currentPos=movePlan1[currentMarker1]; if (moveAmt1>0){
flowRate+=rooms[movePlan1[currentMarker1++]].flowValue; std::cout<<" Moving to "<<movePlan1[currentMarker1]<<" in "<<moveAmt1<<" steps"<<std::endl;
if (currentMarker1<movePlan1.size()){ } else {
moveAmt1=rooms[currentPos].paths[movePlan1[currentMarker1]]; if (moveAmt1==0){
//We open the valve. Then move to the next one.
currentPos=movePlan1[currentMarker1];
path1+="->"+currentPos;
std::cout<<" Path1: "<<path1<<std::endl;
flowRate+=rooms[movePlan1[currentMarker1++]].flowValue;
//flowTotal+=rooms[movePlan1[currentMarker1++]].flowValue;
std::cout<<" Flow rate is now "<<flowRate<<std::endl;
if (currentMarker1<movePlan1.size()){
moveAmt1=rooms[currentPos].paths[movePlan1[currentMarker1]]+1;
std::cout<<" Reached destination. Next: "<<movePlan1[currentMarker1]<<" in "<<moveAmt1<<" steps"<<std::endl;
}
} }
} }
if (moveAmt2==0){ if (moveAmt2>0){
//We open the valve. Then move to the next one. std::cout<<" Moving to "<<movePlan2[currentMarker2]<<" in "<<moveAmt2<<" steps"<<std::endl;
currentPos2=movePlan2[currentMarker2]; } else {
flowRate+=rooms[movePlan2[currentMarker2++]].flowValue; if (moveAmt2==0){
if (currentMarker2<movePlan2.size()){ //We open the valve. Then move to the next one.
moveAmt2=rooms[currentPos2].paths[movePlan1[currentMarker2]]; currentPos2=movePlan2[currentMarker2];
path2+="->"+currentPos2;
std::cout<<" Path2: "<<path2<<std::endl;
flowRate+=rooms[movePlan2[currentMarker2++]].flowValue;
//flowTotal+=rooms[movePlan2[currentMarker2++]].flowValue;
std::cout<<" Flow rate is now "<<flowRate<<std::endl;
if (currentMarker2<movePlan2.size()){
moveAmt2=rooms[currentPos2].paths[movePlan2[currentMarker2]]+1;
std::cout<<" Reached destination. Next: "<<movePlan2[currentMarker2]<<" in "<<moveAmt2<<" steps"<<std::endl;
}
} }
} }
moveAmt1--; moveAmt1--;
moveAmt2--; moveAmt2--;
} }
std::cout<<"Final Flow Total: "<<flowTotal<<std::endl;
if (flowTotal>maxFlow){ if (flowTotal>maxFlow){
maxFlow=flowTotal; maxFlow=flowTotal;
std::cout<<"New max flow is "<<maxFlow<<std::endl; std::cout<<"New max flow is "<<maxFlow<<std::endl;
} }
} }
void permutation(int size, int n){ void printArr2(std::vector<std::string> arr){
for (int i=0;i<arr.size();i++){
if (i!=0){
std::cout<<" ";
}
std::cout<<arr[i];
}
std::cout<<std::endl;
}
void permutation(std::vector<std::string>&arr,int size){
if (size==1){ if (size==1){
printArr(n); printArr();
return; return;
} }
for (int i=0;i<size;i++){ for (int i=0;i<size;i++){
permutation(size-1,n); permutation(arr,size-1);
if (size&1){ if (i<size-1){
swap(targetRooms[i],targetRooms[size-i]); if (size%2==1){
} else { std::swap(arr[0],arr[size-1]);
swap(targetRooms[0],targetRooms[size-1]); } else {
std::swap(arr[i],arr[size-1]);
}
} }
} }
} }
@ -158,7 +198,7 @@ void explore(std::string currentRoom,std::map<std::string,bool>visitedvalves,int
int main() int main()
{ {
std::ifstream file("testinput"); std::ifstream file("input");
while (file.good()){ while (file.good()){
std::string line; std::string line;
std::getline(file,line); std::getline(file,line);
@ -200,8 +240,8 @@ int main()
} }
} }
} }
permutation(targetRooms,targetRooms.size(),targetRooms.size()); permutation(targetRooms,targetRooms.size());

232262
out

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save