From d782c02ec8bfb823eb619f80c601869fa6833850 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Mon, 4 Dec 2023 00:59:24 -0600 Subject: [PATCH] Day 4 completed! --- Day 4/main.cpp | 51 +++++++- .../3159b56254eb6f973bcbb48e59c4c1e/main.cpp | 112 ------------------ 2 files changed, 50 insertions(+), 113 deletions(-) delete mode 100644 enc_temp_folder/3159b56254eb6f973bcbb48e59c4c1e/main.cpp 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