|
|
|
@ -23,16 +23,111 @@ void wait(int pauseMs=0){ |
|
|
|
|
|
|
|
|
|
#pragma endregion |
|
|
|
|
|
|
|
|
|
#include <limits> |
|
|
|
|
const int DAY = 1; |
|
|
|
|
Run runInput=FILE1; |
|
|
|
|
|
|
|
|
|
void doStuff(){ |
|
|
|
|
void doStuff2(){ |
|
|
|
|
while(true){ //lines is accessible as a global.
|
|
|
|
|
std::map<int,std::string>numberWord{ |
|
|
|
|
{0,"zero"},
|
|
|
|
|
{1,"one"}, |
|
|
|
|
{2,"two"}, |
|
|
|
|
{3,"three"}, |
|
|
|
|
{4,"four"}, |
|
|
|
|
{5,"five"}, |
|
|
|
|
{6,"six"}, |
|
|
|
|
{7,"seven"}, |
|
|
|
|
{8,"eight"}, |
|
|
|
|
{9,"nine"}, |
|
|
|
|
}; |
|
|
|
|
int sum=0; |
|
|
|
|
int lineCount=0; |
|
|
|
|
for(std::string&line:lines){ |
|
|
|
|
|
|
|
|
|
lineCount++; |
|
|
|
|
int digitFrontIndex=-1; |
|
|
|
|
int digitBackIndex=-1; |
|
|
|
|
std::array<int,10>wordDigitIndexFront; |
|
|
|
|
std::array<int,10>wordDigitIndexBack; |
|
|
|
|
wordDigitIndexFront.fill(-1); |
|
|
|
|
wordDigitIndexBack.fill(-1); |
|
|
|
|
for(int i=0;i<10;i++){ |
|
|
|
|
wordDigitIndexFront[i]=line.find(numberWord[i]); |
|
|
|
|
} |
|
|
|
|
for(int i=0;i<10;i++){ |
|
|
|
|
wordDigitIndexBack[i]=line.rfind(numberWord[i]); |
|
|
|
|
} |
|
|
|
|
for(int i=0;i<line.size();i++){ |
|
|
|
|
if(line[i]>='0'&&line[i]<='9'){ |
|
|
|
|
digitFrontIndex=i; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
for(int i=line.size()-1;i>=0;i--){ |
|
|
|
|
if(line[i]>='0'&&line[i]<='9'){ |
|
|
|
|
digitBackIndex=i; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
int lowestFrontIndex=std::numeric_limits<int>::max(); |
|
|
|
|
int highestBackIndex=std::numeric_limits<int>::min(); |
|
|
|
|
int frontDigit=0; |
|
|
|
|
int backDigit=0; |
|
|
|
|
for(int i=0;i<10;i++){ |
|
|
|
|
if(wordDigitIndexFront[i]==std::string::npos)continue; |
|
|
|
|
if(lowestFrontIndex>wordDigitIndexFront[i]){ |
|
|
|
|
lowestFrontIndex=wordDigitIndexFront[i]; |
|
|
|
|
frontDigit=i; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if(digitFrontIndex!=-1&&lowestFrontIndex>digitFrontIndex){ |
|
|
|
|
lowestFrontIndex=digitFrontIndex; |
|
|
|
|
frontDigit=line[digitFrontIndex]-'0'; |
|
|
|
|
} |
|
|
|
|
for(int i=0;i<10;i++){ |
|
|
|
|
if(wordDigitIndexBack[i]==std::string::npos)continue; |
|
|
|
|
if(highestBackIndex<wordDigitIndexBack[i]){ |
|
|
|
|
highestBackIndex=wordDigitIndexBack[i]; |
|
|
|
|
backDigit=i; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if(digitBackIndex!=-1&&highestBackIndex<digitBackIndex){ |
|
|
|
|
highestBackIndex=digitBackIndex; |
|
|
|
|
backDigit=line[digitBackIndex]-'0'; |
|
|
|
|
} |
|
|
|
|
sum+=frontDigit*10+backDigit; |
|
|
|
|
std::cout<<lineCount<<std::endl; |
|
|
|
|
if(frontDigit<=0||backDigit<=0||frontDigit>=10||backDigit>=10)throw; |
|
|
|
|
std::cout<<frontDigit<<backDigit<<"/"<<sum<<std::endl; |
|
|
|
|
} |
|
|
|
|
std::cout<<sum<<std::endl; |
|
|
|
|
break; |
|
|
|
|
//wait(0); //Wait for 0ms and render the screen (calls draw())
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
wait(0); //Wait for 0ms and render the screen (calls draw())
|
|
|
|
|
void doStuff(){ |
|
|
|
|
while(true){ //lines is accessible as a global.
|
|
|
|
|
int sum=0; |
|
|
|
|
int digitFront=0; |
|
|
|
|
int digitBack=0; |
|
|
|
|
for(std::string&line:lines){ |
|
|
|
|
for(int i=0;i<line.size();i++){ |
|
|
|
|
if(line[i]>='0'&&line[i]<='9'){ |
|
|
|
|
digitFront=line[i]-'0'; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
for(int i=line.size()-1;i>=0;i--){ |
|
|
|
|
if(line[i]>='0'&&line[i]<='9'){ |
|
|
|
|
digitBack=line[i]-'0'; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
sum+=digitBack*10+digitFront; |
|
|
|
|
//std::cout<<digitFront<<digitBack<<"/"<<sum<<std::endl;
|
|
|
|
|
} |
|
|
|
|
std::cout<<sum<<std::endl; |
|
|
|
|
break; |
|
|
|
|
//wait(0); //Wait for 0ms and render the screen (calls draw())
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -71,7 +166,7 @@ public: |
|
|
|
|
|
|
|
|
|
bool OnUserUpdate(float fElapsedTime) override |
|
|
|
|
{ |
|
|
|
|
static std::thread aocSolver(&AoC2023::doStuff,this); |
|
|
|
|
static std::thread aocSolver(&AoC2023::doStuff2,this); |
|
|
|
|
|
|
|
|
|
if(waitForRender){ |
|
|
|
|
draw(); |
|
|
|
|