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": [ "tasks": [
{ {
"type": "cppbuild", "type": "cppbuild",
"label": "C/C++: gcc build active file", "label": "C/C++: cl.exe build active file",
"command": "/usr/bin/g++", "command": "cl.exe",
"args": [ "args": [
"--std", "/Zi",
"gnu++23", "/EHsc",
"-fdiagnostics-color=always", "/nologo",
"-g", "/Fe${fileDirname}\\${fileBasenameNoExtension}.exe",
"${file}", "${file}"
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
], ],
"options": { "options": {
"cwd": "${fileDirname}" "cwd": "${fileDirname}"
}, },
"problemMatcher": [ "problemMatcher": [
"$gcc" "$msCompile"
], ],
"group": { "group": {
"kind": "build", "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 <string>
#include <vector> #include <vector>
#include <sstream> #include <sstream>
#include <iterator>
using namespace std; using namespace std;
@ -30,6 +31,7 @@ int main(){
currentLevels.push_back(number); currentLevels.push_back(number);
} }
list<int> currentLevelsBackup = currentLevels;
int numOfLevelsInLine = currentLevels.size(); int numOfLevelsInLine = currentLevels.size();
int numOfLevelsProcessed = 0; int numOfLevelsProcessed = 0;
auto curListIt = currentLevels.begin(); auto curListIt = currentLevels.begin();
@ -44,13 +46,16 @@ int main(){
list<int>levelStaysSame; list<int>levelStaysSame;
int totalChange=0; 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(); auto frontIt = currentLevels.begin();
frontIt++; frontIt++;
auto backIt = currentLevels.begin(); auto backIt = currentLevels.begin();
for(int index = 1;frontIt!=currentLevels.end();index++){ for(int index = 1;frontIt!=currentLevels.end();index++){
int change = (*backIt)-(*frontIt); int change = (*frontIt) - (*backIt);
totalChange+=change; totalChange+=change;
changeFromPrevLevel.push_back(change); changeFromPrevLevel.push_back(change);
frontIt++; frontIt++;
@ -63,20 +68,36 @@ int main(){
levelStaysSame.push_front(index); levelStaysSame.push_front(index);
} }
} }
float averageChange = totalChange/(currentLevels.size()-1); float averageChange = totalChange/(currentLevels.size()-1); //we use average change to smooth out the data
//need to pull the first one to have something to compare to
int prevlevel = currentLevels.front(); if (totalChange>0){
currentLevels.pop_front(); dir= UP;
numOfLevelsProcessed++; } else if (totalChange<0){
if (prevlevel < currentLevels.front()){
dir = DOWN; 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(); currentLevels.clear();
} }
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()){ for (int level = currentLevels.front(); !currentLevels.empty();level=currentLevels.front()){
if (abs(prevlevel-level)>3) {currentLevels.clear();break;} if (abs(prevlevel-level)>3) {currentLevels.clear();break;}
@ -92,6 +113,8 @@ int main(){
safeReports++; safeReports++;
} }
} }
}
} }
cout << safeReports; cout << safeReports;
puzzle.close(); puzzle.close();

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.