Day 6 part 2 complete!

master
sigonasr2 12 months ago
parent c1edfcc969
commit e149c7c472
  1. 65
      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::vector<int>time;
std::vector<int>distance;
std::vector<long long>time;
std::vector<long long>distance;
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;i<time.size();i++){
long long targetTime=time[i];
long long targetDist=distance[i];
long long wins=0;
for(long long holdTime=0;holdTime<=targetTime;holdTime++){
long long timeRemaining=targetTime-holdTime;
long long speed=holdTime;
long long distanceTraveled=speed*timeRemaining;
if(distanceTraveled>targetDist){
wins++;
}
}
if(sum==0){
sum=wins;
}else{
sum*=wins;
}
}
std::cout<<sum<<std::endl;
break;
//wait(0); //Wait for 0ms and render the screen (calls draw())
}
}
void doStuff(){
while(true){ //lines is accessible as a global.

Loading…
Cancel
Save