diff --git a/2/puzzle2p2.cpp b/2/puzzle2p2.cpp index cb14d1b..e436701 100644 --- a/2/puzzle2p2.cpp +++ b/2/puzzle2p2.cpp @@ -10,8 +10,9 @@ using namespace std; enum Direction { UP, - DOWN -}; + DOWN, + UNSET +}; int main(){ string line; @@ -32,9 +33,13 @@ int main(){ int numOfLevelsInLine = currentLevels.size(); int numOfLevelsProcessed = 0; auto curListIt = currentLevels.begin(); - curListIt++; //point to second item in list + curListIt++; //point to second item in list + auto RevCurListIt = currentLevels.rbegin(); + RevCurListIt++; //points to second to last item enum Direction dir; bool dirSet =false; + bool listDirty =false; + //check first number, second number and last number to see if they all acend or deced //if not check second number, third number and last number to see if they accend or decend @@ -48,13 +53,28 @@ int main(){ dir= UP; dirSet=true; } - //first item bad + //check ends first. if(!dirSet){ int secondItem = (*curListIt); - curListIt++; //points to thirdlist item + curListIt++; //points to thirdlist item from front + int secondToLastItem = (*RevCurListIt); + RevCurListIt++;//points to 3rd to last item if((secondItem>(*curListIt)&&(secondItem>currentLevels.back()))){ - currentLevels.pop_front()//remove first item + dir=DOWN; + dirSet=true; + currentLevels.pop_front();//remove first item + listDirty=true; + } else if((secondItem<(*curListIt)&&(secondItemcurrentLevels.back()&&(currentLevels.front()>secondToLastItem))){ + dir = DOWN; + dirSet= true; } + //check if the back item is the problem + } //need to pull the first one to have something to compare to