counting each number now

This commit is contained in:
Seth Samuel 2024-12-03 18:58:51 +13:00
parent 55f05e4f16
commit 625cb4986f
2 changed files with 23 additions and 36 deletions

BIN
2/puzzle2p2 Executable file

Binary file not shown.

View file

@ -37,46 +37,33 @@ int main(){
auto RevCurListIt = currentLevels.rbegin();
RevCurListIt++; //points to second to last item
enum Direction dir;
bool dirSet =false;
bool listDirty =false;
list<int>changeFromPrevLevel;
list<int>levelGoesUp;
list<int>levelGoDown;
list<int>levelStaysSame;
int totalChange=0;
changeFromPrevLevel.push_front(0);
auto frontIt = currentLevels.begin();
frontIt++;
auto backIt = currentLevels.begin();
//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
//then check first number, second number and second to last to see if they accend or decend
//set direction
if ((currentLevels.front()>currentLevels.back())&&(*curListIt) > currentLevels.back()){
dir = DOWN;
dirSet=true;
} else if((currentLevels.front()<currentLevels.back())&&((*curListIt)<currentLevels.back())){
dir= UP;
dirSet=true;
for(int index = 1;frontIt!=currentLevels.end();index++){
int change = (*backIt)-(*frontIt);
totalChange+=change;
changeFromPrevLevel.push_back(change);
frontIt++;
backIt++;
if (change>0){
levelGoesUp.push_front(index);
} else if(change<0){
levelGoDown.push_front(index);
} else {
levelStaysSame.push_front(index);
}
//check ends first.
if(!dirSet){
int secondItem = (*curListIt);
curListIt++; //points to thirdlist item from front
int secondToLastItem = (*RevCurListIt);
RevCurListIt++;//points to 3rd to last item
if((secondItem>(*curListIt)&&(secondItem>currentLevels.back()))){
dir=DOWN;
dirSet=true;
currentLevels.pop_front();//remove first item
listDirty=true;
} else if((secondItem<(*curListIt)&&(secondItem<currentLevels.back()))){
dir = UP;
dirSet= true;
currentLevels.pop_front();
listDirty=true;
} else if ((currentLevels.front()>currentLevels.back()&&(currentLevels.front()>secondToLastItem))){
dir = DOWN;
dirSet= true;
}
//check if the back item is the problem
}
float averageChange = totalChange/(currentLevels.size()-1);
//need to pull the first one to have something to compare to
int prevlevel = currentLevels.front();