first test removing single number that is diffrent to the rest

This commit is contained in:
Seth Samuel 2024-12-09 15:19:14 +13:00
parent 625cb4986f
commit d24974703f
12 changed files with 56 additions and 40 deletions

View file

@ -1,5 +0,0 @@
{
"files.associations": {
"*.tcc": "cpp"
}
}

18
.vscode/tasks.json vendored
View file

@ -2,22 +2,20 @@
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc build active file",
"command": "/usr/bin/g++",
"label": "C/C++: cl.exe build active file",
"command": "cl.exe",
"args": [
"--std",
"gnu++23",
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
"/Zi",
"/EHsc",
"/nologo",
"/Fe${fileDirname}\\${fileBasenameNoExtension}.exe",
"${file}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
"$msCompile"
],
"group": {
"kind": "build",

BIN
2/puzzle2.exe Normal file

Binary file not shown.

BIN
2/puzzle2.ilk Normal file

Binary file not shown.

BIN
2/puzzle2.obj Normal file

Binary file not shown.

BIN
2/puzzle2.pdb Normal file

Binary file not shown.

View file

@ -5,6 +5,7 @@
#include <string>
#include <vector>
#include <sstream>
#include <iterator>
using namespace std;
@ -30,6 +31,7 @@ int main(){
currentLevels.push_back(number);
}
list<int> currentLevelsBackup = currentLevels;
int numOfLevelsInLine = currentLevels.size();
int numOfLevelsProcessed = 0;
auto curListIt = currentLevels.begin();
@ -44,13 +46,16 @@ int main(){
list<int>levelStaysSame;
int totalChange=0;
changeFromPrevLevel.push_front(0);
//we are going to walk the levels and see what the change is.
//the frontIt is the front number (starts at 2nd entry)
//backIt is the first entry (starts at 1st entry)
auto frontIt = currentLevels.begin();
frontIt++;
auto backIt = currentLevels.begin();
for(int index = 1;frontIt!=currentLevels.end();index++){
int change = (*backIt)-(*frontIt);
int change = (*frontIt) - (*backIt);
totalChange+=change;
changeFromPrevLevel.push_back(change);
frontIt++;
@ -63,34 +68,52 @@ int main(){
levelStaysSame.push_front(index);
}
}
float averageChange = totalChange/(currentLevels.size()-1);
//need to pull the first one to have something to compare to
float averageChange = totalChange/(currentLevels.size()-1); //we use average change to smooth out the data
int prevlevel = currentLevels.front();
currentLevels.pop_front();
numOfLevelsProcessed++;
if (prevlevel < currentLevels.front()){
if (totalChange>0){
dir= UP;
} else if (totalChange<0){
dir = DOWN;
} else if (prevlevel > currentLevels.front()){
dir = UP;
} else {
}
if (dir==UP&&levelGoDown.size()>2){ //if the overall direction goes up and more then 2 leves go down the list is bad
currentLevels.clear();
} else if (dir==DOWN&&levelGoesUp.size()>2){ //same as above but opiosite dirrection
currentLevels.clear();
}
for (int level = currentLevels.front(); !currentLevels.empty();level=currentLevels.front()){
if (abs(prevlevel-level)>3) {currentLevels.clear();break;}
if(prevlevel==level){ currentLevels.clear();break;}
if(dir==UP&&(prevlevel<currentLevels.front())) {currentLevels.clear();break;}
if(dir==DOWN&&(prevlevel>currentLevels.front())) {currentLevels.clear();break;}
prevlevel=currentLevels.front();
currentLevels.pop_front();
numOfLevelsProcessed++;
if(numOfLevelsProcessed==numOfLevelsInLine){
safeReports++;
if (!currentLevels.empty()){
if (dir==UP&&levelGoDown.size()==1){
list<int>::iterator itNumberToDelete = currentLevels.begin();
advance(itNumberToDelete,levelGoDown.front());
currentLevels.erase(itNumberToDelete);
listDirty = true;
} else if (dir==DOWN&&levelGoesUp.size()==1){
auto itNumberToDelete = currentLevels.begin();
advance(itNumberToDelete,levelGoesUp.front());
currentLevels.erase(itNumberToDelete);
listDirty=true;
}
//need to pull the first one to have something to compare to
int prevlevel = currentLevels.front();
currentLevels.pop_front();
for (int level = currentLevels.front(); !currentLevels.empty();level=currentLevels.front()){
if (abs(prevlevel-level)>3) {currentLevels.clear();break;}
if(prevlevel==level){ currentLevels.clear();break;}
if(dir==UP&&(prevlevel<currentLevels.front())) {currentLevels.clear();break;}
if(dir==DOWN&&(prevlevel>currentLevels.front())) {currentLevels.clear();break;}
prevlevel=currentLevels.front();
currentLevels.pop_front();
numOfLevelsProcessed++;
if(numOfLevelsProcessed==numOfLevelsInLine){
safeReports++;
}
}
}
}
cout << safeReports;

BIN
2/puzzle2p2.exe Normal file

Binary file not shown.

BIN
2/puzzle2p2.ilk Normal file

Binary file not shown.

BIN
2/puzzle2p2.obj Normal file

Binary file not shown.

BIN
2/puzzle2p2.pdb Normal file

Binary file not shown.

BIN
2/vc140.pdb Normal file

Binary file not shown.