diff --git a/Day 4/main.cpp b/Day 4/main.cpp index 60f4bce..aef3bc8 100644 --- a/Day 4/main.cpp +++ b/Day 4/main.cpp @@ -26,6 +26,55 @@ void wait(int pauseMs=0){ const int DAY = 4; Run runInput=FILE2; +void doStuff2(){ + while(true){ //lines is accessible as a global. + int sum=0; + std::vectorscratchcards; + int scratchcardIndex=0; + for(std::string&line:lines){ + if(scratchcards.size()<=scratchcardIndex){ + scratchcards.push_back(1); + }else{ + scratchcards[scratchcardIndex]++; + } + sum++; + std::vectorwinningNumbersList; + size_t colonPos=line.find(':')+1; + std::string winningNumbers=line.substr(colonPos,line.find('|')-colonPos-1); + while(winningNumbers.length()>0){ + std::string numb=winningNumbers.substr(0,3); + int number=atoi(numb.c_str()); + winningNumbersList.push_back(number); + winningNumbers=winningNumbers.substr(3); + } + std::string pickedNumbers=line.substr(line.find('|')+1); + int score=0; + int winningIndex=scratchcardIndex+1; + + while(pickedNumbers.length()>0){ + std::string numb=pickedNumbers.substr(0,3); + int number=atoi(numb.c_str()); + if(std::find(winningNumbersList.begin(),winningNumbersList.end(),number)!=winningNumbersList.end()){ + for(int i=0;i