From e149c7c47255e0bc7ffefc92b10c5185afa002d2 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Tue, 5 Dec 2023 23:32:14 -0600 Subject: [PATCH] Day 6 part 2 complete! --- Day 6/main.cpp | 65 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 3 deletions(-) diff --git a/Day 6/main.cpp b/Day 6/main.cpp index a5c4db6..bb28859 100644 --- a/Day 6/main.cpp +++ b/Day 6/main.cpp @@ -24,10 +24,69 @@ void wait(int pauseMs=0){ #pragma endregion const int DAY = 6; -Run runInput=FILE1; +Run runInput=FILE2; -std::vectortime; -std::vectordistance; +std::vectortime; +std::vectordistance; + +void doStuff2(){ + while(true){ //lines is accessible as a global. + bool firstLine=true; + for(std::string&line:lines){ + if(firstLine){//Time line. + std::string data=line.substr(5); + std::string numb=""; + while(data.length()>0){ + if(data[0]>='0'&&data[0]<='9'){ + numb+=data[0]; + } + data=data.substr(1); + } + if(numb.length()>0){ + time.push_back(std::stoll(numb)); + numb=""; + } + firstLine=false; + }else{//Distance line. + std::string data=line.substr(9); + std::string numb=""; + while(data.length()>0){ + if(data[0]>='0'&&data[0]<='9'){ + numb+=data[0]; + } + data=data.substr(1); + } + if(numb.length()>0){ + distance.push_back(std::stoll(numb)); + numb=""; + } + } + } + long sum=0; + for(int i=0;itargetDist){ + wins++; + } + } + if(sum==0){ + sum=wins; + }else{ + sum*=wins; + } + } + std::cout<